mvc:favicon.ico 是否也在寻找控制器?
我收到错误:
“路径‘/favicon.ico’的控制器未找到或未实现 IController”
然后我想:框架如何知道它必须为哪些文件实例化控制器,因为同样的事情对于脚本,css和其他文件?
(从来没想过这一点,但现在图标正在抱怨,我想知道......)
但是回到错误,为什么会发生这种情况?
I get an error:
"The controller for path '/favicon.ico' was not found or does not implement IController"
Then I thought: how does the framework know for which files it has to instantiate a controller, because the same thing is true for script, css and other files?
(never thought of that, but now the favicon is complaining, I was wondering....)
But back to the error, why does that occur?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将其添加到您的 global.asax 中:
Add this to you global.asax:
您还可以指定带有约束的忽略路由
You can also specify the ignore route with constraints
最上面的答案是正确的。
但对于较新版本的 MVC,您必须将其添加到 RouteConfig.cs 中 RegisterRoutes 方法的顶部(因此在调用 paths.MapRoute(..) 之前的某个位置)。
The top answers are correct.
But for newer versions of MVC you must add this at the top of the RegisterRoutes method in RouteConfig.cs (so somewhere before routes.MapRoute(..) is called).
您可能会通过 VS Web 服务器获得此信息。正确的?
您不会通过 IIS 获得此信息,因为 IIS(默认情况下)处理图像请求(.ico、.jpg、.gif 等),因此它们不会发送到您的应用程序。
You are probably getting this with the VS web server. Right?
You wouldn't get this with IIS since IIS (by default) handles requests for images (.ico, .jpg, .gif, et cetera) and therefore they don't make it to your app.
听起来很有趣,只有当我检查了
tools->options->debugging
下的“Enable Just My Code”选项时,我才会收到此错误,并且一旦取消选中它,我就不再出现此错误。但请注意,该错误似乎仍在幕后抛出,但在内部立即被捕获,因此最好的解决方案是在 global.asax 中编码以忽略它,就像其他答案所建议的那样。
Interesting as it sounds I got this error only if I had checked the "Enable Just My Code" option under
tools->options->debugging
, and as soon as I unchecked it I am no longer getting this error.Note however that it appears that the error is still being thrown behind the scenes but being caught immediately internally, so the best solution is to code in the global.asax to ignore it as the other answers suggest.