我有一个具有区域的MVC 2站点,假设该区域的名称为{Admin}
该地区和该站点工作正常。
我想做的是为该区域设置不同的默认页面。
当我调用时http://webSiteName 可以正常工作
但是对于 http://webSiteName/Admin 我遇到了错误
我尝试了ASP.NET MVC 2 RC 2 returns Area-specific controller when no area specified的解决方案
但没有运气。
我也尝试过
routes.MapRoute(
"Admin",
"{controller}/{action}/{id}",
new { controller = "AdminHome", action = "index" },
new[] { "Web.Areas.Admin.Controllers" }
);
和
routes.MapRoute(
"Admin",
"Admin",
new { controller = "AdminHome", action = "index" },
new string[] { "Web.Areas.Admin.Controllers" }
);
但我仍在获取找不到资源。
我究竟做错了什么?
最佳答案
试试这个。当您的Area命名为/Areas/Admin/AdminAreaRegistration.cs
时,请确保它将在Admin
中。
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "AdminHome",action = "Index", id = "" }
);
}
您无需在
Global.asax
中添加任何内容。