Reputation:
I am using URL Routing for my application and would like to prevent URL Routing from happening on any thing starting with staff/ but using the following code it does not work, how can I get ASP.Net to prevent URL Routing from touching the staff dir and it's sub dirs?
private static void RegisterRoutes(RouteCollection Routes)
{
//URLs to ignore routeing on
RouteTable.Routes.Ignore("staff/");
//Good routes
Routes.MapPageRoute("Reviews", "{Category}/{RouteName}/Reviews.aspx", "~/RouteFiles/Reviews.aspx");
Routes.MapPageRoute("Races", "{Category}/{RouteName}/Races.aspx", "~/RouteFiles/Races.aspx");
Routes.MapPageRoute("SectionHomePage", "{Category}/{RouteName}", "~/RouteFiles/SectionHomePage.aspx");
}
Upvotes: 1
Views: 104
Reputation: 13018
If you are using WebForms and not MVC, which I assume, try using StopRoutingHandler:
routes.Add(new Route("staff/", new StopRoutingHandler()));
Using Routes.Ignore
may work in MVC (not sure about that), but it does not work in a WebForms application.
By assigning the StopRoutingHandler as the default handler for this path, you basically tell the application that all request should be handled by this Handler, which blocks all following attempts to route within this directory.
Upvotes: 1