开发者

asp.net Webforms MapPageRoute order of precedence

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.

ro开发者_Python百科utes.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?


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜