1

I am working with URL's in MVC4, as my question is can we give name for URL's in MVC4 like for example user want to go "Ask Question' section, then on click website redirected to 'stackoverflow.com/questions/ask'.

But I want to show user as 'stackoverflow.com/questions' only. I want to name like for every URL's action. is this possible in MVC 4.

Please help me anyone. Thanks in Advance.

Developer
  • 876
  • 5
  • 18
  • 44

1 Answers1

2

The route will handle all "stackoverflow.com/questions" URL requests. Make sure this route is placed above the catchall default route. If not, this route will never be triggered. Additional route customization could be found here.

routes.MapRoute(
    name: "questions",
    url: "questions/{id}",
    defaults: new
    {
        controller = "questions",
        action = "ask",
        id = UrlParameter.Optional
    }
);
WorkSmarter
  • 3,738
  • 3
  • 29
  • 34
  • Thanks, but is there any other option to show only 'stackoverflow.com' instead of 'stackoverflow.com/questions' and other URL's – Developer Mar 30 '15 at 07:11
  • Take a look at this similar post http://stackoverflow.com/questions/29330258/how-to-avoid-home-in-the-url – WorkSmarter Mar 30 '15 at 07:16
  • If you are interested in hiding the application's URLs, look into the use of nested iframes. The parent iframe would reside at the root of stackoverflow. The child would be hidden with the URLs necessary to make the application work. http://www.w3schools.com/tags/tag_iframe.asp – WorkSmarter Mar 30 '15 at 14:39