C# & ASP.NET MVC area based custom routing

Viewed 39

I am working on an ASP.NET MVC (v5.2.7) application where I have an area named Public.

Now I want to set the default page of the application as follows Public/Controller/Action.

I am unable to set the right RouteConfig.cs file.

My current files are as follows:

PublicAreaRegistration.cs

public class PublicAreaRegistration : AreaRegistration 
{
    public override string AreaName 
    {
        get { return "Public"; }
    }

    public override void RegisterArea(AreaRegistrationContext context) 
    {
        context.MapRoute(
            "Public_default",
            "Public/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional }
        );
    }
}

My RouteConfig.cs:

public static void RegisterRoutes(RouteCollection routes)
{
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.Add(new LDashedRoute("{controller}/{action}/{id}",
            new RouteValueDictionary(
              new { controller = "Home", action = "Index", id = UrlParameter.Optional }),
              new DRouteHandler(),
              new[] { "SBO.Controllers" }
          ));
}
0 Answers
Related