Keith Adler
Keith Adler

Reputation: 21178

Route to controller

I have a controller called Admin with a number of Actions. In the URL, they look like this:

http://www.website.com/Admin/Users/1

http://www.website.com/Admin/Roles/123

Is there anyway to alias out so that:

http://www.website.com/Users/1

http://www.website.com/Roles/123

Automatically goes to the right controller?

Regards.

Upvotes: 1

Views: 201

Answers (1)

Tomas Aschan
Tomas Aschan

Reputation: 60564

Not without interfering with the default route, unless you are not going to use the names Users or Roles anywhere else. If that is the case, you can just add

routes.MapRoute(
    "AdminUsers",
    "Users/{id}",
    new { controller = "Admin", action = "Users", id = "" });

routes.MapRoute(
    "AdminRoles",
    "Roles/{id}",
    new { controller = "Admin", action = "Roles", id = "" });

to your Global.asax.cs file.

Upvotes: 5

Related Questions