MVC 区域 - 非区域路由解析为区域
我已在我的 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 来尝试解决它。当我导航到登录页面时,调试器显示:
- AppRelativeCurrentExecutionFilePath: ~Login
- Admin/{controller}/{action}/{id} 不匹配 当前请求
- {controller}/{action}/{id } 匹配 当前请求
- 匹配的路由:{controller}/{action}/{id}
到目前为止一切顺利。但随后它显示:
- 使用路由“Admin/{controller}/{action}/{id}”生成的 URL: /Admin/Login?ReturnUrl=%2F
接下来我登录。我的 Login/Index 方法未命中,并且调试器显示:
- AppRelativeCurrentExecutionFilePath: ~Login
- Admin/{controller}/{action}/{id} Does Not Match Current Request
- {controller}/{action}/{id} 匹配 当前请求
- 匹配路由:{controller}/{action}/{id}
- 生成的 URL:/Admin/Login?ReturnUrl=%2FAdmin%2F使用路由“Admin/{controller}/{action”登录}/{id}"
一方面,它表示它与管理路由不匹配,然后在生成的 URL 中,它表示它正在使用该路由。我很困惑。
I have added an area to my MVC 3 project. I cannot seem to get routing working with a very simple scenario. It seems to always want to resolve to the area. Here is my configuration. At startup:
AreaRegistration.RegisterAllAreas();
IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Browse", action = "Index", id = UrlParameter.Optional }
And
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 }
);
}
}
In web.config:
<authentication mode="Forms">
<forms loginUrl="~/Login" defaultUrl="~/Browse" timeout="60" cookieless="UseDeviceProfile" />
</authentication>
I am using RouteDebugger to try to solve it. When I navigate to the Login page the debugger shows:
- AppRelativeCurrentExecutionFilePath: ~Login
- Admin/{controller}/{action}/{id} Does Not Match Current Request
- {controller}/{action}/{id} Matches Current Request
- Matched Route: {controller}/{action}/{id}
So far so good. But then it shows this:
- Generated URL: /Admin/Login?ReturnUrl=%2F using the route "Admin/{controller}/{action}/{id}"
Next I log in. My Login/Index method is not hit, and the debugger shows:
- AppRelativeCurrentExecutionFilePath: ~Login
- Admin/{controller}/{action}/{id} Does Not Match Current Request
- {controller}/{action}/{id} Matches Current Request
- Matched Route: {controller}/{action}/{id}
- Generated URL: /Admin/Login?ReturnUrl=%2FAdmin%2FLogin using the route "Admin/{controller}/{action}/{id}"
On the one hand it says that it does not match the Admin route, then in the generated URL it says it's using that route. I'm stumped.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将具有预定义值的区域参数添加到路由定义中...例如,而不是:
使用:
让我知道是否有帮助...
问候
Try to add your area parameter with a predefined value to your routing definition... For example instead of:
use:
Let me know if it helps...
Regards