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?
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
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly