我得到了一个“不实现IController”错误的图像和机器人。txt在MVC2

时间:2022-01-21 05:56:18

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

我在webserver上犯了一个奇怪的错误,似乎每个文件都是。aspx文件。

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

这是一个例子。只是替换' /机器人。使用任何。jpg名称或。gif或其他什么,你就会明白:

The controller for path '/robots.txt' was not found or does not implement IController.

路径的控制器/机器人。txt没有被发现或没有实现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.

另外,这是一个混合的MVC和WebForms站点,如果这能起到作用的话。

6 个解决方案

#1


72  

You can ignore robots.txt and all the aspx pages in your routing.

你可以忽略的机器人。txt和所有的aspx页在你的路由。

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.

哈克从源。

#2


15  

The ignore route given above didn't work for me but I found a similar one that did:

上面给出的忽略路径并不适合我,但我发现了一个类似的方法:

routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\.(css|js|gif|jpg)(/.*)?" });

#3


6  

This error could also happen if inside a view in your area, you use the Html.Action helper. This helper will always use the area as a prepend, unless you specifically tell it not to. E.g.,

如果在您所在区域的视图中使用Html,也会发生此错误。行动辅助。这个助手将始终使用该区域作为prepend,除非您明确地告诉它不要这样做。例如,

@Html.Action("Main", "Navigation", new { area = string.Empty })

#4


2  

I found another solution too... While I don't think I'll use it, it's worth showing here in the answers:

我也找到了另一个解决办法……虽然我不认为我会用它,但值得在这里展示一下答案:

The following should (in theory) ignore looking for controllers for anything with a '.' in it.

下面应该(理论上)忽略用a来查找控制器。”。

routes.MapRoute(
    "Default",                                              // Route name
    "{controller}/{action}/{id}",                           // URL with parameters
    new { controller = "Home", action = "Index", id = "" },  // Parameter defaults
    new { controller = @"[^\.]*" }                          // Parameter contraints.
);

#5


2  

Do you still have:

你还有:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

... in your Global.asax.cs?

…在你的Global.asax.cs吗?

MVC puts it there by default, and it's supposed to handle this.

MVC默认设置它,它应该处理这个。

If you do, then the problem may be how you're mixing MVC and WebForms.

如果你这样做了,那么问题可能就是你如何混合MVC和WebForms。

#6


0  

I encountered this error when I request resources that did not exist.

当我请求不存在的资源时,我遇到了这个错误。

Specifically, I was requesting a custom IE css file:

具体来说,我是在请求一个定制的IE css文件:

<!--[if lt IE 8]>@Styles.Render("~/Content/ie7.css")<![endif]-->

< !——(如果lt IE 8)> @Styles.Render(~ /内容/ ie7.css)< !(endif)- - >

(These are condition comments, interpreted by IE)

(这是由IE解释的条件注释)

However, the actual resource existed on ~/Content/ie/ie7.css.

但是,实际的资源存在于~/内容/ie7.css中。

So, without any modifications to the routing, the error was solved by using the correct url of the resource.

因此,如果没有对路由进行任何修改,就可以使用资源的正确url来解决这个错误。

#1


72  

You can ignore robots.txt and all the aspx pages in your routing.

你可以忽略的机器人。txt和所有的aspx页在你的路由。

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.

哈克从源。

#2


15  

The ignore route given above didn't work for me but I found a similar one that did:

上面给出的忽略路径并不适合我,但我发现了一个类似的方法:

routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\.(css|js|gif|jpg)(/.*)?" });

#3


6  

This error could also happen if inside a view in your area, you use the Html.Action helper. This helper will always use the area as a prepend, unless you specifically tell it not to. E.g.,

如果在您所在区域的视图中使用Html,也会发生此错误。行动辅助。这个助手将始终使用该区域作为prepend,除非您明确地告诉它不要这样做。例如,

@Html.Action("Main", "Navigation", new { area = string.Empty })

#4


2  

I found another solution too... While I don't think I'll use it, it's worth showing here in the answers:

我也找到了另一个解决办法……虽然我不认为我会用它,但值得在这里展示一下答案:

The following should (in theory) ignore looking for controllers for anything with a '.' in it.

下面应该(理论上)忽略用a来查找控制器。”。

routes.MapRoute(
    "Default",                                              // Route name
    "{controller}/{action}/{id}",                           // URL with parameters
    new { controller = "Home", action = "Index", id = "" },  // Parameter defaults
    new { controller = @"[^\.]*" }                          // Parameter contraints.
);

#5


2  

Do you still have:

你还有:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

... in your Global.asax.cs?

…在你的Global.asax.cs吗?

MVC puts it there by default, and it's supposed to handle this.

MVC默认设置它,它应该处理这个。

If you do, then the problem may be how you're mixing MVC and WebForms.

如果你这样做了,那么问题可能就是你如何混合MVC和WebForms。

#6


0  

I encountered this error when I request resources that did not exist.

当我请求不存在的资源时,我遇到了这个错误。

Specifically, I was requesting a custom IE css file:

具体来说,我是在请求一个定制的IE css文件:

<!--[if lt IE 8]>@Styles.Render("~/Content/ie7.css")<![endif]-->

< !——(如果lt IE 8)> @Styles.Render(~ /内容/ ie7.css)< !(endif)- - >

(These are condition comments, interpreted by IE)

(这是由IE解释的条件注释)

However, the actual resource existed on ~/Content/ie/ie7.css.

但是,实际的资源存在于~/内容/ie7.css中。

So, without any modifications to the routing, the error was solved by using the correct url of the resource.

因此,如果没有对路由进行任何修改,就可以使用资源的正确url来解决这个错误。