buvi suri
buvi suri

Reputation: 183

How to Change Default URL in MVC5

I have one default route in my routeconfig.cs file

 routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

It will hide Home/Index as Url in browser. My target is to display localhost:44300/Login instead of localhost:44300/Home/Index (but internally it will call Home/Index) and I want to hide Home/Details action method as url

Upvotes: 3

Views: 1144

Answers (1)

StepUp
StepUp

Reputation: 38094

You can change your default route to Account controller and to your necessary Action method:

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Account", action = "Login", id =   
            UrlParameter.Optional }
        );

Update:

It is not possible as MVC has a convention that RouteTable should be look like that: controller/action or vice versa.

If you exclude controller from the route, you'll get an exception:

The matched route does not include a 'controller' route value, which is required.

Upvotes: 2

Related Questions