I have 3 areas at the moment (more will come when I get this working): Login
, User
and Admin
. The Default route in Global.asax
go to the index action of the index controller in the login area (Login\Index\Index
) which works fine, this is how I mapped that:
routes.MapRoute(
"Default", // Route name
"{area}/{controller}/{action}/{id}", // URL with parameters
new { area = "Login", controller = "Index", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new[] { typeof(AppName.Areas.Login.Controllers.IndexController).Namespace }
);
each of the 3 areas is registered like this in the AreaRegistration files:
context.MapRoute(
"Admin_default",
"{area}/{controller}/{action}/{id}",
new { area = "Admin", controller = "Index", action = "Index", id = UrlParameter.Optional },
new[] { typeof(AppName.Areas.Admin.Controllers.IndexController).Namespace }
);
The Login controllers index action takes the users login details, looks up the type of user and redirects them to the appropriate area...... at least it should do. From what I can gather searching google, the correct way to redirect to a specific area is this:
return RedirectToAction("Action", "Controller", new { area = UserType });
which doesn't seem to work, it just redirects to Login\Controller\Action
and I can't work out why.
In my attempts to work out what was happening I used this:
var url = Url.Action("Action", "Controller", new { area = "Admin" });
which produced the same Login\Controller\Action
url.
Any help fixing this would be greatly appreciated