0

i have a ApplicationController class with an action called Admin

so my url is www.mysite.com/Application/Admin

is there anyway i can have the routing be www.mysite.com/Admin and go to this method.

i know i can do this by creating an AdminController but for this one function i thought it was easier to just put in another controller

2 Answers 2

3

Put this above your default route:

routes.MapRoute(
    "ShortRoute",
    "{action}",
    new { controller = "Application", action = "Index"}
);
Sign up to request clarification or add additional context in comments.

Comments

1

You can set the Application controller and the Admin method as the default controller and action, using parameter defaults:

routes.MapRoute(
    "Default", // Route name
    "{action}", // URL with parameters
    new { controller = "Application", action = "Admin" }
);

If this is your last route, it will match any request that does not have a controller name and an action name in it. In this particular example, even a request without an action will execute your Admin action, since it's the default action.

Note that routes with parameter defaults can create strange behavior in your existing routes, if you have any. You can always use the ASP.NET MVC Routing Debugger to test which routes match a given URL.

3 Comments

@Robert This is the new route. :)
I don't think this one will match mysite.com/action.
+1 for the route debugger. Everyone who programs in ASP.NET MVC should know about it, and the NerdDinner tutorial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.