Tim*_*ott 7 asp.net-mvc asp.net-mvc-areas asp.net-mvc-3
我在MVC 3项目中添加了一个区域.我似乎无法通过一个非常简单的场景来处理路由.它似乎总是希望解决该地区.这是我的配置.在启动时:
AreaRegistration.RegisterAllAreas();
IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Browse", action = "Index", id = UrlParameter.Optional }
Run Code Online (Sandbox Code Playgroud)
和
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 { controller = "Users", action = "Index", id = UrlParameter.Optional }
);
}
}
Run Code Online (Sandbox Code Playgroud)
在web.config中:
<authentication mode="Forms">
<forms loginUrl="~/Login" defaultUrl="~/Browse" timeout="60" cookieless="UseDeviceProfile" />
</authentication>
Run Code Online (Sandbox Code Playgroud)
我正在使用RouteDebugger来尝试解决它.当我导航到Login页面时,调试器显示:
到现在为止还挺好.但它显示了这一点:
接下来我登录.我的登录/索引方法未命中,调试器显示:
一方面它说它与Admin路由不匹配,然后在生成的URL中它表示它正在使用该路由.我很难过.
尝试将具有预定义值的区域参数添加到您的路由定义中...例如,而不是:
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Users", action = "Index", id = UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
使用:
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { area = "Admin", controller = "Users", action = "Index", id = UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
如果有帮助请告诉我...问候
| 归档时间: |
|
| 查看次数: |
2075 次 |
| 最近记录: |