Davood
Davood

Reputation: 5645

Change controller and action name in ASP.NET MVC routing

I created an areas -> Admin.

In my register area, I have:

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

I changed it to:

context.MapRoute(
    "jojo",
    "jojo/{controller}/{action}/{id}",
    new { action = "Index", id = UrlParameter.Optional }
);

Now if you type in a URL, xxx/jojo/AdminHome/Index, it works perfectly, but how can I change the controller and action names until the user can not finds that it's going to the admin area. Notice that I do not want change my controller name to jojo, for example.

Is it possible?

Upvotes: 2

Views: 3437

Answers (1)

Charles Ouellet
Charles Ouellet

Reputation: 6508

You can do this:

context.MapRoute(
    "jojo",
    "jojo/jojo/{action}/{id}",
    new { controller="RealController", action = "Index", id = UrlParameter.Optional }
);

Upvotes: 4

Related Questions