Favicon路线 [英] Route for favicon
问题描述
我有一个具有多租户解决方案的.net mvc4应用程序. 设置方法是尝试为客户端获取文件,如果找不到,则获取全局文件.
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.
所有这些都很好用,在我的RouteConfig.cs中,我在最底部有这一行:
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是我的自定义类,可加载全局文件或租户文件,并且效果很好. 但是我注意到我从elmah(错误处理程序)中得到了很多错误,如下所示:
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.
因此,我一直在尝试解决此问题,但无法解决.如果我将我的线路放在routeconfig中的较高位置,那么它将干扰其他路由(所有路由都变为site.com/favicon.ico?param1 ...)
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...)
我尝试使用routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
但是它不能运行我的代码,因此所有租户都可以获取全局文件.
But then it does not run my code and so all tenants get the global file.
我知道如果您将其链接到收藏夹,则它不再需要位于根目录中,但是我喜欢这种解决方案,其中我的静态文件处理程序选择正确的文件而不是更改文件的路径(我根本不希望代码发送到包含〜/clients/clientA/favicon.ico
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
因此,如果可以通过仅使我的路线更加具体化而解决问题,那么它就很好,那么它只会在根目录中捕获favicon,别无其他.所以我可以将其放在routeconfig.cs的顶部
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
最后,如果有人想从elmah看完整的错误,请在这里: http://db.tt/3QBxIxmb
Finally if anyone want to see the full error from elmah it's here: http://db.tt/3QBxIxmb
推荐答案
此答案是否有帮助: https://stackoverflow.com/a/2501352/1586498
routes.Add(new Route("favicon.ico", new StopRoutingHandler()));
关闭Firefox,清除历史记录,然后重试."
"Close Firefox, clear history and try again."
这篇关于Favicon路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!