我已经为我的MVC 3项目添加了一个区域。我似乎无法让路由使用非常简单的场景。它似乎总是想要解决这个地区。这是我的配置。在启动时:
AreaRegistration.RegisterAllAreas();
IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Browse", action = "Index", id = UrlParameter.Optional }和
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 }
);
}
}在web.config中:
<authentication mode="Forms">
<forms loginUrl="~/Login" defaultUrl="~/Browse" timeout="60" cookieless="UseDeviceProfile" />
</authentication>我正在使用RouteDebugger来解决这个问题。当我导航到登录页面时,调试器显示:
到目前一切尚好。但它显示了:
使用路由"Admin/{controller}/{action}/{id}"生成的
接下来我就登录。没有命中我的Login/Index方法,调试器显示:
一方面它说它与Admin路由不匹配,然后在生成的URL中它说它正在使用该路由。我很困惑。
发布于 2011-05-04 12:32:59
尝试将带有预定义值的区域参数添加到路由定义中.例如:而不是:
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Users", action = "Index", id = UrlParameter.Optional }
);用途:
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { area = "Admin", controller = "Users", action = "Index", id = UrlParameter.Optional }
);如果有帮助请告诉我..。问候
https://stackoverflow.com/questions/5695797
复制相似问题