views:

201

answers:

1

I am attempting to use the MapPageRoute feature in Visual Studio 2010 and .NET Framework 4.0 with a asp.net webforms application.

What I have noticed is that if I define a page route called "Default" like below and the page Default.aspx exists in the project, then the route does not work.

        routes.MapPageRoute("Default", "default.aspx", "~/Page2.aspx");
        routes.MapPageRoute("Test", "test.aspx", "~/Page2.aspx");

If I change the name of the Default.aspx in the project to Default_1.aspx, then the route works fine.

There seems to be some order of precedence going on. Is there a way to make my route definitions evaluated first so I don't have to rename my pages to use the routing engine?

A: 

There's a property on the RouteCollection called RouteExistingFiles, which is set to false by default. This explains why the Default route doesn't work if you have a default.aspx page.

If you insert routes.RouteExistingFiles = true; before your lines of code, it would make the routes take priority. I'm not 100% sure whether it would then fall back to files if it couldn't route - I guess it depends on the routes you have set up...

Jon
setting routes.RouteExistingFiles = true did the trick. thanks.