mvc:favicon.ico 是否也在寻找控制器?

发布于 2024-10-10 16:07:21 字数 216 浏览 1 评论 0原文

我收到错误:

“路径‘/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

一身骄傲 2024-10-17 16:07:21

将其添加到您的 global.asax 中:

routes.IgnoreRoute("favicon.ico");

Add this to you global.asax:

routes.IgnoreRoute("favicon.ico");
奢欲 2024-10-17 16:07:21

您还可以指定带有约束的忽略路由

routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

You can also specify the ignore route with constraints

routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
温柔戏命师 2024-10-17 16:07:21

最上面的答案是正确的。

routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

但对于较新版本的 MVC,您必须将其添加到 RouteConfig.csRegisterRoutes 方法的顶部(因此在调用 paths.MapRoute(..) 之前的某个位置)。

The top answers are correct.

routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

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).

蹲在坟头点根烟 2024-10-17 16:07:21

您可能会通过 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.

回忆那么伤 2024-10-17 16:07:21

听起来很有趣,只有当我检查了 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文