代码之家  ›  专栏  ›  技术社区  ›  Ben Lesh

我在MVC2中的images和robots.txt上收到一个“notimplementicontroller”错误

  •  52
  • Ben Lesh  · 技术社区  · 16 年前

    路径“/robots.txt”的控制器 未找到或未实现 I控制器。

    我确信这与我如何设置路由有关,但我不确定我到底需要做些什么。

    此外,这是一个混合了MVC和WebForms的站点,如果这有区别的话。

    6 回复  |  直到 16 年前
        1
  •  77
  •   Daniel A. White    16 年前

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

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

    你也可以忽略favicon。

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

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

    从学校毕业 source .

        2
  •  17
  •   The Coder    14 年前

    routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\.(css|js|gif|jpg)(/.*)?" });
    
        3
  •  6
  •   Daniel gnclmorais    15 年前

    如果在您所在区域的视图中使用Html.Action帮助程序,也可能发生此错误。此助手将始终使用该区域作为前置词,除非您明确告诉它不要这样做。例如。,

    @Html.Action("Main", "Navigation", new { area = string.Empty })
    
        4
  •  2
  •   Ben Lesh    16 年前

    我发现 another solution

    以下内容(理论上)应忽略为任何带有“.”的对象查找控制器。

    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
  •   Craig Stuntz    16 年前

    你还有:

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

    ... 在您的Global.asax.cs中?

    MVC默认将它放在那里,它应该处理这个问题。

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

        6
  •  1
  •   R. Schreurs Rohith    13 年前

    我在请求不存在的资源时遇到此错误。

    具体地说,我请求一个自定义IE css文件:

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

    condition comments

    但是,实际的资源存在于~/Content/ie/ie7.css上。

    因此,在不修改路由的情况下,通过使用正确的资源url解决了错误。