简体   繁体   中英

ASP.Net Routing with WebForms

I am trying to cut over an existing WebForms app to use Routing, and want to do it in phases. However, I am running into some issues with a particular route:

//I want to catch existing calls to .aspx pages, but force them through  
// a route, so I can eventually drop the .aspx extension  
new Route("{page}.aspx", new MyCustomRoute());

This isn't working at all, as calls to [SomePage].aspx are never tripping this route... If I change the route to look like this:

//Same thing sans .aspx extension
new Route("{page}", new MyCustomRoute());

All calls to [SomePage] are getting picked up. Any ideas?

Ok, so now I feel stupid...

Turns out there is this little property on the RouteCollection class called RouteExistingFiles which is false by default. Apparently ASP.Net routing gives precedence to existing files before turning them over to routing, so any calls to existing pages would obviously not be handled by my routes. Setting this property to true resolves my issue, all though it may have unintended side effects to which I am as of yet unaware.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM