Я решил эту проблему, выполнив следующее.
В моем Global.asax.cs у меня есть
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
}
protected void Application_Start()
{
//Initialise IoC
IoC.Initialise();
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
В моем PublicAreaRegistration.cs (Public Area), у меня есть
public class PublicAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Public";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute("Root", "", new { controller = "Home", action = "Index" });
context.MapRoute(
"Public_default",
"Public/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
, new[] { "<Project Namespace here>.Areas.Public.Controllers" }
);
}
}
В моем AuthAreaRegistration.cs (Область для ограниченного доступа) у меня есть
public class AuthAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Auth";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Auth_default",
"Auth/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
И, наконец, мои ссылки на моих * .cshtml страницах будут выглядеть как
1) @ Html.ActionLink («Log Off», «LogOff», new {area = «Public», controller = «Home»})
или
2) @ Html.ActionLink ("Область администратора", "Индекс", новый {area = "Auth", controller = "Home"})
Надеюсь, это сэкономит кому-то часы исследований! Кстати, я говорю о MVC3 здесь.
Kwex.