Stoping URL Routing from happening on certain directorys and anything it contains, including sub-directorys

StackOverflow https://stackoverflow.com//questions/12699923

Question

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");
}
Was it helpful?

Solution 2

The solution is to make an RouteTable.Routes.Ignore() entry.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top