views:

33

answers:

2

Hello!

Is there anyway to make all actions in a given controller to redirect to the server root?

For example, if I have a URL with controller Home and action terms I want that to the URL to become /terms

If I have another URL with controller Home and action privacy, then the URL should become /privacy.

I am able to do this by hard-coding 2 routes, but is there a way to automatically do this?

routes.MapRoute(
    "Term",
    "terms",
    new { controller = "Home", action = "terms" }
 );

routes.MapRoute(
    "Privacy",
    "privacy",
    new { controller = "Home", action = "privacy" }
);
A: 

Hard coding the two routes is the automatic way.

Hogan
I don't see anything automatic in hardcoding :-)
Darin Dimitrov
True, but it is easier than having to write an http handler or module.
Hogan
Who said that you have to write an http handler or module?
Darin Dimitrov
@Darin : clearly not you since you know how to write it as one line of code -- from my perspective just being able to use MapRoute is easier than the ways I've had to do it for years. Yes I was being flip :)
Hogan
+4  A: 
routes.MapRoute(
    "ActionOnly",
    "{action}",
    new { controller = "Home" }
);
Darin Dimitrov
awesome.. it worked! thank you!
AbeP