Jake Stout
Jake Stout

Reputation: 476

In my MVC 3 .NET application, how do I change the URL in the address bar on website startup?

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?

Upvotes: 1

Views: 1276

Answers (6)

Henk Holterman
Henk Holterman

Reputation: 273284

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.

Upvotes: 2

chris
chris

Reputation: 31

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

Upvotes: 0

Erik Philips
Erik Philips

Reputation: 54638

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?

Upvotes: 2

Akash KC
Akash KC

Reputation: 16310

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
        );

Upvotes: 1

SliverNinja - MSFT
SliverNinja - MSFT

Reputation: 31651

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

Upvotes: 0

48klocs
48klocs

Reputation: 6103

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

Upvotes: 0

Related Questions