Wednesday, October 19, 2011

Routing except webforms requests

I have a legacy webforms (.aspx) project that I'm sliding routing and MVC3 into. I needed a route that would not prevent the default page from being handled by IIS, but would allow all other controller style routing.  How do you make a regex that only fails uri's that have .aspx or .axd in them?

Then I thought well I still don't want anything that doesn't look like an mvc route (things that end in .foo or .fooo)  Sounds like a crazy negative regex.
Here's the regular expression:


Match anything that doesn't look like a file extension 

And here's the routeAdd in global.asax

static void RegisterRoutes(RouteCollection routes)

     routes.MapRoute("mvc", "{controller}/{action}/{id}",defaults: new{action="index",id=""}, constraints:new{controller=@"^(.(?!\.[a-zA-Z0-9]{3,}))*$"});


No comments:

Post a Comment