tags:

views:

527

answers:

4

In Global.asax what does

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); signify?

A: 

It tells the routing engine to ignore this request and leave it to ASP.NET Webforms to handle things.

This is useful for example ELMAH logging that uses the handler elmah.axd.

David Liddle
+2  A: 

Without this ASP.NET would try to map all requests to AXD handlers to controllers and actions. Having the ignoreRoute means the URL will not map the URL to a controller as per the default behaviour.

RichardOD
+2  A: 

An .axd file is a virtual file that is handled by an HTTP Handler. They are used for (amongst other things) delivering various resources to the webpage, such as automatically generated javascript for AJAX controls and the like.

As these are virtual files, you do not want the routing engine to try to map these requests to controllers. You need them to be executed directly by ASP.NET.

That is what the line achieves.

Greg B
+7  A: 

This is one of the really frustrating things about learning MVC - the documentation for this feature is awful - there's just hardly anything there: http://msdn.microsoft.com/en-us/library/dd470170(VS.100).aspx.

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

This allows all the something.axd files to run outside of MVC - that "{*pathInfo}" at the end allows query strings to be ignored (it's kind of a wildcard).

Note that this doesn't apply any such wildcard to the path, so:

trace.axd?clear=1 //excluded from MVC

mySubFolder/customResource.axd //MVC passed to mySubFolderController.customResource()

Helpful. I've been unable to find any decent documentation on exactly what is and isn't supported as keywords apart from "{resource}" and "{*pathInfo}"

However there is an almost completely undocumented feature that gives you a lot more control over these ignored routes:

//ignore all WebForms .aspx/.asmx/.ashx calls anywhere
routes.IgnoreRoute( "{*allaspx}", new { allaspx = @".*\.as[pmh]x(/.*)?" } );

If you pass an anon-initialised object with a property, that property becomes a keyword that you can use in the route.

You can't pass a regex in the route, but you can in this anon property.

Keith