942,515 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 1870
  • ASP.NET RSS
Jul 2nd, 2009
0

One Time Ambiguous Controller - ASP.NET MVC

Expand Post »
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:
ASP.NET Syntax (Toggle Plain Text)
  1. public static void RegisterRoutes(RouteCollection routes)
  2. {
  3. routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  4.  
  5.  
  6. routes.MapLowerCaseAreasEmployees("{controller}/{action}/{id}",
  7. "EsgRepublic.Payport.Mvc",
  8. new[] { "Employees" });
  9.  
  10. routes.MapLowerCaseAreasDefaultEmployees("{action}/{id}", "EsgRepublic.Payport.Mvc", new[] { "Employees" });
  11.  
  12.  
  13.  
  14. routes.MapLowerCaseAreas("{controller}/{action}/{id}",
  15. "EsgRepublic.Payport.Mvc",
  16. new[] { "Admin" });
  17.  
  18.  
  19. routes.MapLowerCaseRootArea("{controller}/{action}/{id}",
  20. "EsgRepublic.Payport.Mvc",
  21. new { controller = "Home", action = "Index", id = "" });
  22. }

My Map.. methods:
ASP.NET Syntax (Toggle Plain Text)
  1. public static void MapLowerCaseAreas(this RouteCollection routes, string url, string rootNamespace, string[] areas)
  2. {
  3. routes.MapLowerCaseAreas(url, rootNamespace, areas,
  4. new RouteValueDictionary(new { action = "Index", controller = "Home", id = "" }));
  5. }
  6.  
  7. public static void MapLowerCaseAreas(this RouteCollection routes, string url, string rootNamespace, string[] areas, RouteValueDictionary defaults)
  8. {
  9. Array.ForEach(areas, area =>
  10. {
  11. Route route = new LowercaseRoute("{area}/" + url, new MvcRouteHandler())
  12. {
  13. Constraints = new RouteValueDictionary(new { area }),
  14. Defaults = defaults
  15. };
  16. string areaNamespace = rootNamespace + ".Areas." + area + ".Controllers";
  17.  
  18. route.DataTokens = new RouteValueDictionary(new { namespaces = new string[] { areaNamespace } });
  19.  
  20. routes.Add(route);
  21. });
  22.  
  23. }
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. public static void MapLowerCaseAreasEmployees(this RouteCollection routes, string url, string rootNamespace, string[] areas)
  32. {
  33. Array.ForEach(areas, area =>
  34. {
  35. Route route = new LowercaseRoute("{area}/" + url, new MvcRouteHandler())
  36. {
  37. Constraints = new RouteValueDictionary(new { area, controller="BankAccount|Home|W4Tax|I9Tax"}),
  38. Defaults = new RouteValueDictionary(new {action = "Index", id = "" })
  39. };
  40. string areaNamespace = rootNamespace + ".Areas." + area + ".Controllers";
  41.  
  42. route.DataTokens = new RouteValueDictionary(new { namespaces = areaNamespace });
  43.  
  44. routes.Add(route);
  45.  
  46.  
  47. });
  48.  
  49.  
  50.  
  51.  
  52.  
  53. }
  54.  
  55. public static void MapLowerCaseAreasDefaultEmployees(this RouteCollection routes, string url, string rootNamespace, string[] areas)
  56. {
  57. Array.ForEach(areas, area =>
  58. {
  59. Route route = new LowercaseRoute("{area}/" + url, new MvcRouteHandler())
  60. {
  61. Constraints = new RouteValueDictionary(new { area}),
  62. Defaults = new RouteValueDictionary(new { controller = "Employee",action = "Index", id = "" })
  63. };
  64. string areaNamespace = rootNamespace + ".Areas." + area + ".Controllers";
  65.  
  66. route.DataTokens = new RouteValueDictionary(new { namespaces = areaNamespace });
  67.  
  68. routes.Add(route);
  69.  
  70.  
  71. });
  72.  
  73.  
  74.  
  75.  
  76.  
  77. }
  78.  
  79. public static void MapLowerCaseRootArea(this RouteCollection routes, string url, string rootNamespace, object defaults)
  80. {
  81. Route route = new LowercaseRoute(url, new MvcRouteHandler())
  82. {
  83. Constraints = new RouteValueDictionary(new {controller="Home|", area="root|"}),
  84. Defaults = new RouteValueDictionary(new { area = "root", action = "Index", controller = "Home", id = "" })
  85. };
  86. route.DataTokens = new RouteValueDictionary(new { namespaces = new string[] { rootNamespace + ".Controllers" } });
  87. // route.Defaults = new RouteValueDictionary(new { area = "root", action = "Index", controller = "Home", id = "" });
  88. routes.Add(route);
  89. }

Thanks in advance for your help
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Vegetalzis is offline Offline
2 posts
since Jul 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Can anyone explain this line of code for me?
Next Thread in ASP.NET Forum Timeline: fileupload authorization error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC