William
William

Reputation: 3395

Change Project URL Visual Studio

I would like to be able to debug my ASP.NET MVC application on a domain other than localhost as well as any subdomains, in other words:

http://domain.dev http://*.domain.dev

I have tried the following:

  1. Modify the Hosts file
  2. Add a Host record for *.domain.dev that returns 127.0.0.1
  3. Change the 'Project Url' in the project properties.

However, nothing is working. When I start to debug I get a page that either says "Service Unavailable" or "Invalid URL".

What am I missing?

p.s. I am using Visual Studio 2013

Upvotes: 13

Views: 62952

Answers (2)

njfife
njfife

Reputation: 3575

For Visual Studio 2015 the steps in the above answers apply but the applicationhost.config file is in a new location. in your "solution" folder follow the path

\.vs\config

Within that folder you will see your applicationhost.config file

Alternatively you could just search your solution folder for the .config file and find it that way.

I personally used the following configuration:

enter image description here

With the following in my hosts file:

127.0.0.1       jam.net
127.0.0.1       www.jam.net

And the following in my applicationhost.config file:

<site name="JBN.Site" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Dev\Jam\shoppingcart\src\Web\JBN.Site" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:49707:" />
            <binding protocol="http" bindingInformation="*:49707:localhost" /> 
    </bindings>
</site>

Remember to run your instance of visual studio 2015 as an administrator! If you don't want to do this every time I recomend this:

How to Run Visual Studio as Administrator by default

I hope this helps somebody, I had issues when trying to upgrade to visual studio 2015 and realized that none of my configurations were being carried over.

Upvotes: 19

dom
dom

Reputation: 6832

You need to actually create a new record for each subdomain in the hosts file. You can't use wildcards.

127.0.0.1 domain.dev
127.0.0.1 foo.domain.dev
127.0.0.1 bar.domain.dev

Although it seems that it can be done with some extra work, see this question for more details.

You also need to include the port number when accessing the URL. The browser would point to http://foo.domain.dev:0000, using the port number assigned in VS, of course.

If you are using the Visual Studio Development Server, that's all there is to it. If using IIS Express, it takes a bit more work.

VS project properties

Then you need to make sure you have a record in the IIS applicationhost.config file :

<site name="YourApplication" id="25">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Path\To\Your\App" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:2750:foo.domain.dev" />
    </bindings>
</site>

Update

<site name="DomainProject" id="18">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Users\William\Source" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:32939:domain.dev" />
        <binding protocol="http" bindingInformation="*:32939:domain2.dev" />
    </bindings>
</site>

Upvotes: 8

Related Questions