【问题标题】:The controller path for '/null' was not found or does not implement IController找不到“/null”的控制器路径或未实现 IController
【发布时间】:2020-07-20 01:22:34
【问题描述】:

我已将 RouteConfig.RegisterRoutes(RouteTable.Routes); 添加到其 global.asax 文件中的现有 asp.net 网络表单应用程序。我正在尝试在表单旁边使用一些 MVC——比如友好的 url。代码非常标准,包括:

 public static void RegisterRoutes(RouteCollection routes)
 {
     var settings = new FriendlyUrlSettings { AutoRedirectMode = RedirectMode.Permanent };
     routes.EnableFriendlyUrls(settings, new MyFriendlyUrlResolver());

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

     routes.MapRoute(
             name: "Default",
             url: "{controller}/{action}/{id}",
             defaults: new { action = "Index", id = UrlParameter.Optional }
         );
 }

除了自定义友好的 url 解析器之外,这几乎都是样板代码,所以我不明白为什么我会收到很多“找不到 '/null' 的控制器路径或没有实现 IController”错误现在。

我现在是否获得了大量访问 www.mysite.com/null 的流量,还是这与路由有关?是否有一种特殊的方法可以为表单繁重的网站设置路由?我已经使用表单 + MVC 创建了新的应用程序,这几乎是项目附带的代码。

【问题讨论】:

    标签: asp.net asp.net-mvc webforms asp.net-mvc-routing


    【解决方案1】:

    首先要确定你的路线,如果你的路线是

    localhost/Home/Index
    

    还要确保在文件 aspx.cs 后面的代码中继承控制器类,如 公共类 Customer : Controller,然后在您的操作方法上放置一个断点 就在这里

     localhost/Customer/Add 
    

    然后检查您的 aspx(设计)页面是否路由到正确的 URL 一般在MVC中

     @Html.Action("Add", "Customer ", Model).
    

    检查您的 global.asax 文件 Application_onstart 事件并确保这两行按此顺序出现

    GlobalConfiguration.Configure(WebApiConfig.Register);            
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    

    【讨论】:

      猜你喜欢
      • 2012-12-10
      • 2013-05-31
      • 1970-01-01
      • 2016-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多