ASP.NET MVC Routing: How do I redirect all actions to Base Url?

Up vote 2 down vote favorite 1 share g+ share fb share tw.

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" } ); asp. Net-mvc asp.

Net-mvc-routing link|improve this question asked Sep 2 '10 at 21:51Abe885625 87% accept rate.

Routes. MapRoute( "ActionOnly", "{action}", new { controller = "Home" } ).

Awesome.. it worked! Thank you! – Abe Sep 2 '10 at 22:40.

Hard coding the two routes is the automatic way.

I don't see anything automatic in hardcoding :-) – Darin Dimitrov Sep 2 '10 at 21:56 True, but it is easier than having to write an http handler or module. – Hogan Sep 2 '10 at 22:00 Who said that you have to write an http handler or module? – Darin Dimitrov Sep 2 '10 at 22:00 @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 Sep 2 '10 at 9:17.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions