I have successfully setup routing in Asp.Net 4.0 webforms. I have set up:
routeCollection.MapPageRoute("Default Page", "Default/{ProductName}/{CategoryName}", "~/Default.aspx");
However, problem is even though the user browses to default.aspx, the page still shows up. How can I avoid this? I want only the MapPageRoute to work. I want that when user browses to default.aspx some error should be thrown or 404 page should be shown etc. In short I do not the user to browse through default.aspx. How can I do this?
Thanks in advance 🙂
you can handle this issue through two ways.
In global.asax in Request_Start event check that if the requested url end by .aspx redirect to error page.
Use Url rewriter, by regular expression identify the wrong requests and redirect them to custom error page.