In Global.asax what does the following signify?
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With