1

When I start debugging my MVC web application, the URL in my address bar is the following:

http://localhost:#####/

And this calls the Home/Index route. Is there a way to have the Home/Index part included when I start debugging in the address bar like this:

http://localhost:#####/Home/Index

I don't quite understand why the address does not display the Home/Index part in the first place. Can someone clarify this?

tereško
  • 58,060
  • 25
  • 98
  • 150
Jake Stout
  • 487
  • 1
  • 5
  • 17

6 Answers6

2

Just set it up in Project|Properties:

enter image description here

Select Specific page and set it to: Home/Index

But do consider how a real visitor will be coming to your site, and what you want to happen.

H H
  • 263,252
  • 30
  • 330
  • 514
2

I don't quite understand why the address does not display the Home/Index part in the first place. Can someone clarify this?

The reason is that the in the design of MVC, the authors most likely decided that hiding information that wasn't useful would be best.

For example both of these are run the same action on the same controller with the default routes:

http://localhost:xxxx/
http://localhost:xxxx/Home/Index

What is the advantage of the second one? It's longer?

So by default if the route matches or partial matches it's removed from the url.

With the default controllers (with a AboutController), the following urls are also the same:

http://localhost:xxxx/About
http://localhost:xxxx/About/Index

Again, whats the advantage of the second one?

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
1

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
        );
Akash KC
  • 16,057
  • 6
  • 39
  • 59
0

You almost certainly have a default route set up in global.asax.cs.

48klocs
  • 6,073
  • 3
  • 27
  • 34
0

Assign the Start URL (Absolute) or Specific Page (Relative) in the Web Tab of your project properties.

Start Action -> Start URL : http://localhost:#####/Home/Index

Community
  • 1
  • 1
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
0

There is no advantage to the second one. The second path is being used as the default path for the first.

chris
  • 31
  • 2