I'm getting a “Does not implement IController” error on images and robots.txt in MVC2

后端 未结 6 2149
滥情空心
滥情空心 2020-12-04 09:12

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

相关标签:
6条回答
  • 2020-12-04 09:24

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

    Specifically, I was requesting a custom IE css file:

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

    (These are condition comments, interpreted by IE)

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

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

    0 讨论(0)
  • 2020-12-04 09:28

    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.

    0 讨论(0)
  • 2020-12-04 09:29

    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.

    routes.MapRoute(
        "Default",                                              // Route name
        "{controller}/{action}/{id}",                           // URL with parameters
        new { controller = "Home", action = "Index", id = "" },  // Parameter defaults
        new { controller = @"[^\.]*" }                          // Parameter contraints.
    );
    
    0 讨论(0)
  • 2020-12-04 09:32

    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.Action("Main", "Navigation", new { area = string.Empty })
    
    0 讨论(0)
  • 2020-12-04 09:42

    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)(/.*)?" });
    
    0 讨论(0)
  • 2020-12-04 09:43

    Do you still have:

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

    ... in your Global.asax.cs?

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

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

    0 讨论(0)
提交回复
热议问题