我在ASP.NET MVC 5中有一個路由問題。我創建兩個區域「公共」和「管理」,我在URL localhost/Example中設置Public/NewsController/Index默認站點。 WebUI中,但現在我不能使用localhost/Example.WebUI /聯繫...... 我與T4MVC代碼: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 }
);
}
}
註冊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);
}
}
你能幫助我嗎?