ASP.NET routing - GetRouteData not working if path exists

I have HttpModuleone that intercepts all requests and loads data from a database based on routing rules. However, I run into one problem all the time; GetRouteDataonly works if the path does not exist:

var routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current));

Assuming a query is being requested for url http://localhost/contact, I get the correct routing data related to this url if this path does not exist on the file system. The problem occurs when I want to configure the page on this url that I am doing by creating an aspx page in the path ~/contact/default.aspx. As soon as I do this, GetRouteDatareturn it null.

I even tried to create a new object HttpContext, but I still cannot get the route data if the page exists.

Has anyone encountered this problem? Is there a solution / workaround?

All help would be greatly appreciated.

+3
source share
1 answer

Set RouteCollection.RouteExistingFilesto true.

public static void RegisterRoutes(RouteCollection routes)
{
    // Cause paths to be routed even if they exists physically
    routes.RouteExistingFiles = true;

    // Map routes
    routes.MapPageRoute("...", "...", "...");
}

Beware. IIS7 behaves somewhat differently than the server used for debugging in Visual Studio. I realized this when I deployed my application on the Internet. View the feedback sent to Microsoft Connection .

+3
source

All Articles