I need to solve a problem with url rewrite using routing feature in asp.net 4.0.
when user type url like
then right page shows but suppose if i change the page location and name and when user type url like
then page not found error will occur.
So please tell me how could I solve this situation using asp.net 4.0 routing feature.
is it possible ?
I handler routing like and my sample code
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RouteTable.Routes.MapPageRoute
("Source", "Source/{ID}/{Title}", "~/Source.aspx");
RouteTable.Routes.MapPageRoute
("Source1", "MyData/Source/{ID}/{Title}", "~/MyData/Source.aspx");
}
The code above is just sample and I this way do the url rewrite. It is very easy.
But if I need to solve my above url mapping problem with routing then how could I do so and what kind of code I need to write in Application_Start event.
I want when user type
then it should redirect to
This url. So please guide me how could I do this kind of mapping with the help of asp.net 4.0 routing feature.
The only way you can route to a path containing a querystring is to use a custom handler. By default routing passes variables in the RouteData.
So you have 3 options.
1) write a custom route handler to rewrite the path taking RouteData and adding it to the querystring. I wrote some code similar code for this in this question.
2) update MyProduct.aspx to check for product
idin the QueryString if not found inprodidand useMapPageRoute(the new page has access the the original querystring).3) use IIS7 rewrite rules