Reputation: 2017
Problem Statement:
I'm trying to route to a Login view under Area(Test Area) not working.
Exception:
HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory
Most likely causes: A default document is not configured for the requested URL, and directory browsing is not enabled on the server.
If I route to view other than the login view under area it works fine
What I'm doing wrong in routing??
Area:
Test Area Registartion.cs
public class TestAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Test";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Test_default",
"Test/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
}
Roue Config in App_Start :
If I use default route for login it works fine ,but if I give route to login view under test area it gives HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this director why??
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
// Default Route for Login
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Login", action = "Index", id = UrlParameter.Optional }
);
//Area View Route for Login
routes.MapRoute(
name: "Test",
url: "Test/{controller}/{action}/{id}",
defaults: new { controller = "Login", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "WebApplication1.Areas.Test.Controllers" }
);
}
}
Global.asax.cs :
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
Database.SetInitializer<WebApplication1.Areas.Test.Models.Test_DB>(null);
}
Upvotes: 0
Views: 810
Reputation:
Try with this:
routes.MapRoute(
name: "Test",
url: "{controller}/{action}/{id}",
defaults: new {controller = "Login", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "WebApplication1.Areas.Test.Controllers" }).DataTokens["area"] = "Test";
Upvotes: 1