I\'m trying to use areas within MVC app, I would like that the default route will be resolved to the HomeController within the admin area but it resolves to the home controller
This solution will broke your API route. You must have some unique name for each area, like the default area makes it:
context.MapRoute(
"Common_default",
"**Common**/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
The correct solution to default route below:
Web area route:
context.MapRoute(
"Common_default",
"Common/{culture}/{controller}/{action}/{id}",
new {culture = CultureHelper.GetDefaultCulture(), controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Main route which redirect users to the "Common" area:
routes.MapRoute(
name: "Default",
url: "{culture}/{controller}/{action}/{id}",
defaults: new { culture = CultureHelper.GetDefaultCulture(), controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "SMS.Sender.Areas.Common.Controllers" }
).DataTokens.Add("area","Common");