It seems that ASP.NET MVC 3 will serve existing files first before looking at the routing table. This can be turned off by setting the option routes.RouteExistingFiles = true. When it is set to not route existing files, it doesn’t seem to serve all files. For example if a file is named *.cs it will not be served. If the file is renamed to .txt it will be served. I find this rather arbitrary and I haven’t been able to find any documentation about what is served and what is not served. It should have been much better that static file serving was added as an entry in the routing table, with a StaticFileRouteHandler class or something along these lines. Does anyone have more information or details about this subject? I would like to have full control over what my application is serving or not.
P.S: I am using the ASP.NET development server.
You may take a look at the
<httpHandlers>section of yourc:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.configfile. Mine looks like this:So you can see all those forbidden extensions. They correspond to source code files and for security reasons are not served directly. Otherwise people would be able to look at your source code file.
If you wanted to serve them you could write a controller action which would serve those files.