在ASP.NET MVC中处理错误的URL

时间:2018-10-20 18:49:50

标签: asp.net-mvc

我正在使用Areas开发ASP.NET MVC。我有三个区域。但是,默认路由不是区域。运行应用程序时,出现此错误:

Areas_error

路线如下所示:

RouteConfig

        public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            namespaces: new string[] { "SmartSIMS.Web.Controllers" }
        );
    }

区域是:

  1. 管理

        public override void RegisterArea(AreaRegistrationContext context) 
    {
        context.MapRoute(
            name: "Administration_default",
            url: "Administration/{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            namespaces: new string[] { "SmartSIMS.Web.Areas.Administration.Controllers" });
    }
    
  2. 学生

        public override void RegisterArea(AreaRegistrationContext context) 
    {
        context.MapRoute(
            name: "Students_default",
            url: "Students/{controller}/{action}/{id}",
            defaults: new { action = "Index", id = UrlParameter.Optional },
            namespaces: new string[] { "SmartSIMS.Web.Areas.Students.Controllers" });
    }
    
  3. 老师

        public override void RegisterArea(AreaRegistrationContext context) 
    {
        context.MapRoute(
            name: "Teachers_default",
            url: "Teachers/{controller}/{action}/{id}",
            defaults: new { action = "Index", id = UrlParameter.Optional },
            namespaces: new string[] { "SmartSIMS.Web.Areas.Teachers.Controllers" });
    }
    

如何解决此错误?请协助。

1 个答案:

答案 0 :(得分:0)

问题已解决。我将web.config中的RouteDebugger设置为false。非常感谢