Non Area Route Resolves To Area
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:
So far so good. But then it shows this:
Next I log in. My Login/Index method is not hit, and the debugger shows:
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.
Try to add your area parameter with a predefined value to your routing definition... For example instead of:
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Users", action = "Index", id = UrlParameter.Optional }
);
use:
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { area = "Admin", controller = "Users", action = "Index", id = UrlParameter.Optional }
);
Let me know if it helps... Regards
链接地址: http://www.djcxy.com/p/6260.html下一篇: 非区域路线解决区域