I thought I'd got all my routing sorted! Just one little glitch to sort out, but first I need to explain our set-up.
I decided against a catch-all router, and instead am trapping HTTP errors in my web.config file (this question helped). First I turned the old-fashioned CustomErrors off:
<!--<customErrors mode="Off" />-->
Then I turned HTTP error-trapping on:
(as often happens, I couldn't seem to insert this as script). In the interests of full disclosure, my web.config file includes this:
I'm not trapping any application errors in Global.asax.cs. This all works fine - I then have a router which picks up on 404 errors:
routes.MapRoute(
"Error 404",
"Error/MissingPage404",
new { controller = "Error", action = "MissingPage404" }
);
and another for 500 errors:
routes.MapRoute(
"Error 500",
"Error/ServerError500",
new { controller = "Error", action = "ServerError500" }
);
My question is: how can I stop static files being trapped by this? I've already solved the problem for images, thanks to this question, which is to include these lines at the top of my routing config file:
routes.IgnoreRoute("{*allfiles}", new { allfiles = @".*\.(gif|jpg|png|ico)" });
However, the equivalent doesn't work for .js, .ico, .css or .zip files. I tried from another site:
routes.IgnoreRoute("{*allaspx}", new { allaspx = @".*\.css(/.*)?" });
routes.IgnoreRoute("{*allaspx}", new { allaspx = @".*\.ico(/.*)?" });
but that did nothing either. Again in the interests of disclosure, I've got this line at the top of the routing config file, but my understanding is that this only affects files which are found:
routes.RouteExistingFiles = true;
Can anyone help? It seems like MVC is brilliantly thought out, right up until the point of making routing easy to understand and implement.
Many thanks in advance
Andy