URL Rewriting in asp.net MVC


I need functionality like, if user enters http://localhost:5130 default page should be open like user/index

and if user enters http://localhost:5130/customer, customer/index page should be open

 

how can i achieve this in MVC using route.config?


Asked by:- SnehalSawant
0
: 2646 At:- 3/27/2018 3:06:29 PM
asp.net mvc c#

Does the answer below help? please mark it as answer if yes so other users who stumble upon it, gets the idea that it worked for you, If not let me know about the issue you are facing using comment's thanks 0
By : vikas_jk - at :- 3/30/2018 11:24:18 AM






1 Answers
profileImage Answered by:- vikas_jk

You need to create a create MapRoute for each of the URL, above Default route in Route.config suppose, you want to show user/index  as default page, so route should be

routes.MapRoute(
              name: "DefaultNew",
               url: "{controller}/{action}",
               defaults: new { controller = "User", action = "Index" }
           );

for http://localhost:5130/customer add another value in route config above defaultnew/default ruote

 routes.MapRoute(
                name: "PostWithSlug",
                url: "customer",
                defaults: new { controller = "Customer", action = "Index" }
                );

check these links for more help

https://qawithexperts.com/questions/259/show-a-slug-url-without-id-in-the-url-in-aspnet-mvc

https://qawithexperts.com/questions/37/how-can-i-simplify-url-in-net-mvc

Hope this helps

2
At:- 3/27/2018 3:53:41 PM Updated at:- 3/27/2018 3:54:47 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use