Vegetalzis 0 Newbie Poster

Hello everyone. My application has two "main" controllers, which are: 1: EsgRepublic.Payport.Mvc.Areas.Employees.Controllers.EmployeeController
2: EsgRepublic.PayPort.Mvc.Areas.Admin.Controllers.HomeController

The first time i click at any link related to the 1st controller, i get the following error:
The controller name 'Home' is ambiguous between the following types:
EsgRepublic.Payport.Mvc.Areas.Admin.Controllers.HomeController
EsgRepublic.Payport.Mvc.Controllers.HomeController

The second time works properly, and so on.
Strangely, this error only happens the first time i click per clean&build (if i only build, it doesnt happen!). Also, if i click on links about the 2nd controller before the 1st, it works properly.

My global asax:

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


            routes.MapLowerCaseAreasEmployees("{controller}/{action}/{id}",
              "EsgRepublic.Payport.Mvc",
              new[] { "Employees" });

            routes.MapLowerCaseAreasDefaultEmployees("{action}/{id}", "EsgRepublic.Payport.Mvc", new[] { "Employees" });

           

            routes.MapLowerCaseAreas("{controller}/{action}/{id}",
               "EsgRepublic.Payport.Mvc",
               new[] { "Admin" });
           

            routes.MapLowerCaseRootArea("{controller}/{action}/{id}",
                "EsgRepublic.Payport.Mvc",
                new { controller = "Home", action = "Index", id = "" });
        }

My Map.. methods:

public static void MapLowerCaseAreas(this RouteCollection routes, string url, string rootNamespace, string[] areas)
        {
            routes.MapLowerCaseAreas(url, rootNamespace, areas, 
                new RouteValueDictionary(new { action = "Index", controller = "Home", id = "" }));
        }

        public static void MapLowerCaseAreas(this RouteCollection routes, string url, string rootNamespace, string[] areas, RouteValueDictionary defaults)
        {
            Array.ForEach(areas, area =>
            {
                Route route = new LowercaseRoute("{area}/" + url, new MvcRouteHandler())
                {
                    Constraints = new RouteValueDictionary(new { area }),
                    Defaults = defaults
                };
                string areaNamespace = rootNamespace + ".Areas." + area + ".Controllers";
                
                route.DataTokens = new RouteValueDictionary(new { namespaces = new string[] { areaNamespace } });

                routes.Add(route);
            });

        }




      


        public static void MapLowerCaseAreasEmployees(this RouteCollection routes, string url, string rootNamespace, string[] areas)
        {
            Array.ForEach(areas, area =>
            {
                Route route = new LowercaseRoute("{area}/" + url, new MvcRouteHandler())
                {
                    Constraints = new RouteValueDictionary(new { area, controller="BankAccount|Home|W4Tax|I9Tax"}),
                    Defaults = new RouteValueDictionary(new {action = "Index", id = "" })
                };
                string areaNamespace = rootNamespace + ".Areas." + area + ".Controllers";
                
                route.DataTokens = new RouteValueDictionary(new { namespaces =  areaNamespace  });

                routes.Add(route);

               
            });


            

            
        }

        public static void MapLowerCaseAreasDefaultEmployees(this RouteCollection routes, string url, string rootNamespace, string[] areas)
        {
            Array.ForEach(areas, area =>
            {
                Route route = new LowercaseRoute("{area}/" + url, new MvcRouteHandler())
                {
                    Constraints = new RouteValueDictionary(new { area}),
                    Defaults = new RouteValueDictionary(new { controller = "Employee",action = "Index", id = "" })
                };
                string areaNamespace = rootNamespace + ".Areas." + area + ".Controllers";

                route.DataTokens = new RouteValueDictionary(new { namespaces = areaNamespace });

                routes.Add(route);


            });





        }

 public static void MapLowerCaseRootArea(this RouteCollection routes, string url, string rootNamespace, object defaults)
        {
            Route route = new LowercaseRoute(url, new MvcRouteHandler())
            {
                Constraints = new RouteValueDictionary(new {controller="Home|", area="root|"}),
                Defaults = new RouteValueDictionary(new { area = "root", action = "Index", controller = "Home", id = "" })
            };
            route.DataTokens = new RouteValueDictionary(new { namespaces = new string[] { rootNamespace + ".Controllers" } });
          //  route.Defaults = new RouteValueDictionary(new { area = "root", action = "Index", controller = "Home", id = "" });
            routes.Add(route);
        }

Thanks in advance for your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.