Change default URL in address bar in ASP.Net MVC

essitco.dotnet
 
on Nov 07, 2021 11:01 PM
958 Views

Hello everyone I have faced a issue I'm login then redirect my page localhost:333333/PubSearch/Search it's working fine but I have face a issue User enter localhost:333333

this in address bar my Index page open I want to hit this url localhost:333333 in address bar localhost:333333/PubSearch/Search this page open.

I have change in startup.cs file but not working .Please help me

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Nov 08, 2021 03:45 AM
on Feb 17, 2022 09:40 AM

You need to register the route in RegisterRoute method in following way.

routes.MapRoute
(
    "Default",                                              // Route name
    "{controller}/{action}/{id}",                           // URL with parameters
    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
);

Reference

https://stackoverflow.com/questions/33952584/how-to-show-only-controller-name-in-the-case-of-index-action-in-mvc-5-url

https://stackoverflow.com/questions/11439978/in-my-mvc-3-net-application-how-do-i-change-the-url-in-the-address-bar-on-webs