I am using routing in webforms to clean up urls. I store all my .aspx files in the /Pages directory and route to them with clean URLs. As it stands I can still access these files by navigating to /Pages/Home.aspx for example. How can I either throw a 404 or redirect to a different page in my routing table? Here is what I have tried:
routes.RouteExistingFiles = true;
routes.Ignore("{resource}.aspx/{*pathInfo}");
routes.Ignore(@"*\.aspx");
routes.MapPageRoute("Home", "", "~/Pages/Home.aspx");
This isn't working at all, and I could use some advice.
If I try accessing a physical file on my MVC site, I get the following:
Object reference not set to an instance of an object.
Can I do this on webforms?