Default area route not working in mvc 5
I added the default controller and action name but still the default routing is not working for the area. Here is my code:
AreaRegistration.cs
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller ="LogIn", action = "Index", id = UrlParameter.Optional }
);
}
RouteConfig.asax
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.LowercaseUrls = true;
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
When i go to http://webapplocal/admin/ i get the below error: 403 forbidden: A default document is not configured for the requested URL, and directory browsing is not enabled on the server.
I added RouteTable.Routes.RouteExistingFiles = true; in RouteConfig.cs and it worked
This looks like a similar problem I ran into: ASP.NET MVC 4 Parameters Separated by Forward Slashes "/" not passing args properly
I'd recommend adding the MapRoute into the same location as the default MapRoute, in RouteConfig.asax. This is because the routing is order-sensitive and your separate routing routine may never be looked at when the first routing fails.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.LowercaseUrls = true;
routes.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller ="LogIn", action = "Login", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
链接地址: http://www.djcxy.com/p/36768.html
上一篇: c#从datagridview导出数据到excel
下一篇: 默认区域路线在mvc中不起作用5