我得到一个“不实现IController” MVC2中的图像和robots.txt错误 [英] I'm getting a "Does not implement IController" error on images and robots.txt in MVC2

查看:146
本文介绍了我得到一个“不实现IController” MVC2中的图像和robots.txt错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是一个例子,我的网络服务器似乎是一个奇怪的错误。只需用任何.jpg名称或.gif替换'/robots.txt',或者你会得到以下想法:


控制器对于路径/robots.txt
未找到或不实现
IController。


确保这与我如何设置路由有关,但我不知道我需要做什么。



此外,这是一个混合的MVC和WebForms网站,如果这有所作为。

解决方案

您可以忽略robots.txt和路由中的所有aspx页面。

  routes.IgnoreRoute({* allaspx},新的{allaspx = @。* \.aspx(/。 *)})?; 
routes.IgnoreRoute({* robotstxt},新{robotstxt = @(。* /)?robots.txt(/.*)?});

您可能也想忽略图标。

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

您可以调整正则表达式以排除路径。



来源


I'm getting a strange error on my webserver for seemingly every file but the .aspx files.

Here is an example. Just replace '/robots.txt' with any .jpg name or .gif or whatever and you'll get the idea:

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.

Also, this is a mixed MVC and WebForms site, if that makes a difference.

解决方案

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(/.*)?"});

You might want to ignore the favicon too.

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

You can adjust the regular expression to exclude paths.

Haacked from the source.

这篇关于我得到一个“不实现IController” MVC2中的图像和robots.txt错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆