What is routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
I cannot find any .axd file in my project, can I remove this route rule?
What is routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
I cannot find any .axd file in my project, can I remove this route rule?
Some Background
If you open up this file:
you will find this within the file:
That is basically telling the Asp.NET runtime: "Hey asp.net dude, if a request comes for WebResource.axd then use AssemblyResourceLoader to process the request."
Please do note that WebResource.axd is NOT a file but simply a map (if I may say) to
AssemblyResourceLoader
. It is the name under which the handler is registered. On my machine, I found the following .axd handlers:Ok, so what does that handler do?
The
AssemblyResourceLoader
knows how to look for embedded files within an assembly so it can serve it (send it to the client i.e. a browser). For example, in asp.net web forms, if you use the validation controls, they depend on some javascript to show the errors on the web page. However, that javascript is embedded in an assembly. The browser needs the javascript so you will see this in the html of the page:The
AssemblyResourceLoader
will find the assembly where the javascript is embedded using the information in the querystring and return the javascript.Back to the Question
So to answer the question, what is:
That is telling the routing engine that we will not be processing those requests that match that route pattern. In other words, we will not process
.axd
requests. Why? Because MVC itself is an HttpHandler similar to.axd
and.aspx
and many other handlers that are in the web.config file. The MVC handler does not know how to process the request such as looking for embedded resources in an assembly-theAssemblyResourceLoader
knows how to do that. MVC knows how to do, well everything it does which is beyond the scope of this question and answer.Here is a great article which explains
.axd
in more details.The route with the pattern {resource}.axd/{*pathInfo} is included to prevent requests for the Web resource files such as WebResource.axd or ScriptResource.axd from being passed to a controller.
Read link: http://msdn.microsoft.com/en-us/library/cc668201%28v=vs.100%29.aspx
Those are not files (they don't exist on disk) - they are just names under which some HTTP handlers are registered.
Take a look in the below link: http://haacked.com/archive/2008/07/14/make-routing-ignore-requests-for-a-file-extension.aspx
.axd files don't exist physically. ASP.NET uses URLs with .axd extensions (ScriptResource.axd and WebResource.axd) internally, and they are handled by an HttpHandler.
Therefore, you should keep this rule, to prevent ASP.NET MVC from trying to handle the request instead of letting the dedicated HttpHandler do it.