问题
I have a .net mvc4 application that has a multitentant solution. The way this is set up is that it tries to get a file for the client, and if not found it takes the global file.
All this works great and in my RouteConfig.cs I have this line at the very bottom:
routes.Add("FaviconRoute", new Route("favicon.ico", new StaticFileRouteHandler("favicon.ico", "Content", "", true)));
StaticFileRouteHandler is my custom class that loads either global or tenant file and that works great. However I noticed that I get a lot of erros from elmah (error handler) like this:
404 Http The controller for path '/favicon.ico' was not found or does not implement IController.
So I have been trying to fix this but cant figure it out. If I put my line higher in routeconfig then it disturbes other routes (all routes becomes site.com/favicon.ico?param1...)
I have tried using routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
But then it does not run my code and so all tenants get the global file.
I know that favicon no longer needs to be in the root if you link it, but i like this solution where my static file handler selects the right file instead of changing path to the file (I simply don't want the code sent to the client containing a path with like ~/clients/clientA/favicon.ico
So it would be great if it could be solved with simply making my route more specific so it only catches favicon in the root and nothing else. So i can put it at the top of routeconfig.cs
Finally if anyone want to see the full error from elmah it's here: http://db.tt/3QBxIxmb
回答1:
Does this answer help: https://stackoverflow.com/a/2501352/1586498
routes.Add(new Route("favicon.ico", new StopRoutingHandler()));
"Close Firefox, clear history and try again."
来源:https://stackoverflow.com/questions/16759626/route-for-favicon