问题描述
我的文件夹,如下所示:
My folder look like this:
- (根)/区/管理/浏览次数/..
- (根)/地区/行政/控制器/...
-
(根)/Areas/Admin/Routes.cs
- (root)/Areas/Admin/Views/..
- (root)/Areas/Admin/Controllers/...
(root)/Areas/Admin/Routes.cs
(根)/区/论坛/浏览次数/..
(root)/Areas/Forum/Views/..
(根)/Areas/Forum/Routes.cs
(root)/Areas/Forum/Routes.cs
public class Routes : AreaRegistration
{
公众覆盖字符串AREANAME
{
{返回管理; }
}
{ public override string AreaName { get { return "Admin"; } }
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_Default",
"{controller}/{action}/{Id}",
new { controller = "Admin", action = "Index", Id = (string)null }
);
}
}
公共类航线:AreaRegistration
{
公众覆盖字符串AREANAME
{
{返回论坛; }
}
public class Routes : AreaRegistration{ public override string AreaName { get { return "Forum"; } }
public override void RegisterArea(AreaRegistrationContext routes)
{
routes.MapRoute(
"Forum_Default",
"{controller}/{action}",
new { controller = "Forum", action = "Index"}
);
}
}
Global.asax中
Global.asax
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
AreaRegistration.RegisterAllAreas();
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
在起始页应首页/指数,但它与管理员/指数,为什么?
The startpage should be Home/Index but it start with Admin/Index, why?
只有site.com/Admin工作不site.com/Forum
Only site.com/Admin works not site.com/Forum
我应该如何获得管理员和论坛区工作的权利?为什么只有管理员的工作,而不是论坛?
How should i get Admin and Forum Areas to work right? Why is only Admin working and not Forum?
当我删除管理员/ Routes.cs文件论坛开始工作......
When i delete Admin/Routes.cs file Forum start to work...
编辑:
家在〜/查看/不显示为起始页即使我有
Home in ~/Views/ don't show as startpage even if i have
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
在我的Global.asax AreaRegistration.RegisterAllAreas后();
in my Global.asax after AreaRegistration.RegisterAllAreas();
推荐答案
我相信你的区域映射的结构应当像这样。
I believe your area mappings should be structured like so.
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_Default",
"Admin/{controller}/{action}/{Id}",
new { controller = "Admin", action = "Index", Id = (string)null }
);
}
和
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Forum_Default",
"Forum/{controller}/{action}/{Id}",
new { controller = "Forum", action = "Index"}
);
}
保持您的路线从相互矛盾的,这是我认为你的情况正在发生。为您的默认路由匹配您的管理路线。
Keeps your routes from conflicting, which is what i think is happening in your case. As your default route matches your admin route.
这篇关于在asp.net mvc的地区,只有一个兼职工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!