根目录下“Admin”控制器 和 Areas的名也是“admin”该如何访问根目录下的admin控制器问题重点是,区域名和根目录下的控制品重名了要如何解决,不要告诉我换个名字噢,看有啥解决办法RouteConfig.cs文件内容 public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "xxx.WEB.Controllers" } //加了这句可以访问根目录下其它控制器。
);
}
这是区域路由下的文件
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 { action = "Index", id = UrlParameter.Optional },
new string[] { "xxx.WEB.Areas.Admin.Controllers" }
);
}
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "xxx.WEB.Controllers" } //加了这句可以访问根目录下其它控制器。
);
}
这是区域路由下的文件
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 { action = "Index", id = UrlParameter.Optional },
new string[] { "xxx.WEB.Areas.Admin.Controllers" }
);
}
{
context.MapRoute(
this.AreaName + "_Default",
this.AreaName + "/{controller}/{action}/{id}",
new { area = this.AreaName, controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "XXXXX.Web.Areas." + this.AreaName + ".Controllers" }
);
}