0

I am new to ASP.NET MVC5, I found one default route in routeconfig.cs file.

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

so, If I am trying to access localhost:44300, I am redirecting to Home/Index action method.

So I am added Login page in Home/Index view page. after user successful login I am redirecting the user to Home/Details Method then In browser I am getting url as https://localhost:44300/Home/Details.

Here my question Is there any possibility to hide Home/Details like Home/Index. I am tried with adding another default route but it is failed.

buvi suri
  • 173
  • 1
  • 14
  • 1
    You can only have one _'default'_ route. What are you wanting to achieve. Why would you want to _'hide'_ the `Home/Details` route? (making it impossible for the user to navigate to it) –  Jan 09 '16 at 11:05
  • @StephenMuecke yes. I don't want to show `Home/details` route to user (target is to display same url before and after login (https://localhost:44300) ) – buvi suri Jan 09 '16 at 11:08
  • Possible duplicate of [How to mask the controller and action name from the browser?](http://stackoverflow.com/questions/32517047/how-to-mask-the-controller-and-action-name-from-the-browser) – NightOwl888 Jan 09 '16 at 13:05

2 Answers2

1

Try adding following route before your default route in RouteConfig.cs file -

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

This will convert - Home/Details to Home/Index

Nirman
  • 6,715
  • 19
  • 72
  • 139
  • I have the same issue, after adding this I am getting Home/Index instead of Home/Details But there is no possibility to hide Home/Index – Arjun Jan 23 '16 at 12:59
0

It is impossible to have the same url (http://localhost:44300) be mapped to 2 different controller actions. There can only be one default route.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928