我得到一个“不实现 IController".MVC2 中的图像和 robots.txt 错误 [英] I'm getting a "Does not implement IController" error on images and robots.txt in MVC2
问题描述
我的网络服务器上似乎每个文件都出现了一个奇怪的错误,但 .aspx 文件除外.
I'm getting a strange error on my webserver for seemingly every file but the .aspx files.
这是一个例子.只需将 '/robots.txt' 替换为任何 .jpg 名称或 .gif 或其他名称,您就会明白:
Here is an example. Just replace '/robots.txt' with any .jpg name or .gif or whatever and you'll get the idea:
路径/robots.txt"的控制器未找到或未实施控制器.
The controller for path '/robots.txt' was not found or does not implement IController.
我确定这与我设置路由的方式有关,但我不确定我到底需要做什么.
I'm sure it's something to do with how I've setup routing but I'm not sure what exactly I need to do about it.
此外,这是一个混合了 MVC 和 WebForms 的网站,如果这有所不同的话.
Also, this is a mixed MVC and WebForms site, if that makes a difference.
推荐答案
你可以忽略robots.txt和你路由中的所有aspx页面.
You can ignore robots.txt and all the aspx pages in your routing.
routes.IgnoreRoute("{*allaspx}", new {allaspx=@".*.aspx(/.*)?"});
routes.IgnoreRoute("{*robotstxt}", new {robotstxt=@"(.*/)?robots.txt(/.*)?"});
您可能也想忽略图标.
routes.IgnoreRoute("{*favicon}", new {favicon=@"(.*/)?favicon.ico(/.*)?"});
您可以调整正则表达式以排除路径.
You can adjust the regular expression to exclude paths.
来自 来源.
这篇关于我得到一个“不实现 IController".MVC2 中的图像和 robots.txt 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!