ASP.NET MVC 5でルーティングに問題があります。「Public」と「Admin」の2つのエリアを作成し、public/NewsController/index default siteをurl localhost/Exampleに設定します。ASP.NET MVC 5ルーティングエリア
AdminAreaRegistration.cs
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Admin";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { area = MVC.Admin, controller = MVC.Admin.Hierarchy.Name, action = MVC.Admin.Hierarchy.ActionNames.Index, id = UrlParameter.Optional }
);
}
}
PublicAreaRegistration.cs
public class PublicAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Public";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Public_default",
"{controller}/{action}/{id}",
new { controller = MVC.Public.News.Name, action = MVC.Public.News.ActionNames.Index, id = UrlParameter.Optional }
);
}
}
登録します。WebUIが、今、私はT4MVCではlocalhost/Example.WebUI /管理... 私のコードを使用することはできませんRoutes.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { area = MVC.Public.Name, controller = MVC.Public.News.Name, action = MVC.Public.News.ActionNames.Index, id = UrlParameter.Optional },
namespaces: new[] { "Example.WebIU.Areas.Public.Controllers" }
);
routes.MapRoute(
name: "MyRoute",
url: "{controller}/{action}/{id}",
defaults: new { controller = MVC.Admin.Hierarchy.Name, action = MVC.Admin.Hierarchy.ActionNames.Index, id = UrlParameter.Optional },
namespaces: new[] { "Example.WebIU.Areas.Admin.Controllers" }
);
}
そして、Global.asaxの
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AutoMapper.Mapper.Initialize(cfg => cfg.AddProfile<AutomapperProfile>());
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}
あなたは私を助けることができますか?