RegisterRoutes in ASP.NET MVC 4

Магжан Куан

I have two areas Admin and SecurityGuard. Routing shown below. Displays error: System.ArgumentException: The route with the name "Admin_default" is already in the family route. Names must be unique routes. Parameter name: name

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


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

            AreaRegistration.RegisterAllAreas();

        }

Global.asax:
     protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();
        }

AdminAreaRegistration:
      public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "Admin_default",
                "Admin/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional },
                  new { controller = "Slider|Product" },
                namespaces: new[] { "CaterWebsite.Areas.Admin.Controllers" }
            );

         }

SecurityGuardAreaRegistration:
     public override void RegisterArea(AreaRegistrationContext context)
        {

            context.MapRoute("SearchMembership", "SecurityGuard/Membership/index/{searchterm}/{filterby}",
                new { controller = "Membership", action = "Index", searchterm = UrlParameter.Optional, filterby = "all" }
                );

            context.MapRoute("Membership", "SecurityGuard/Membership/{action}/{userName}",
                new { controller = "Membership", userName = UrlParameter.Optional }
                );  

            context.MapRoute(
                "SecurityGuard_default",
                "SecurityGuard/{controller}/{action}/{id}",
                new { controller = "Dashboard", action = "Index", id = UrlParameter.Optional }
            );
        }
NightOwl888

Remove AreaRegistration.RegisterAllAreas(); from your RegisterRoutes method. You are calling it twice.

You have it specified in the right place in your Application_Start method.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related