13

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

Leonardo
  • 10,737
  • 10
  • 62
  • 155
William
  • 3,335
  • 9
  • 42
  • 74

2 Answers2

19

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.

Community
  • 1
  • 1
njfife
  • 3,555
  • 1
  • 20
  • 31
8

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>
Community
  • 1
  • 1
dom
  • 6,702
  • 3
  • 30
  • 35
  • 4
    I already had all of those settings (I just rechecked to make sure it was exactly as you have it). I get the following message: "Unable to launch the IIS Express Web server. The start URL specified is not valid. http://domain.dev:32939" – William Jan 07 '14 at 20:09
  • So I got it to work on *.domain.dev by replacing the default localhost site in the applicationhost.config instead of adding a new one. This takes care of me being able to access the site on multiple subdomains, but what about multiple domains? – William Jan 07 '14 at 20:14
  • Can you post the `` config that you tried to add and didn't work? – dom Jan 07 '14 at 20:51
  • 3
    Doesn't look like any of this applies to VS 2015, since my VS2015 projects don't appear in the config file. – Shimmy Weitzhandler Jul 23 '15 at 01:25
  • See my answer bellow for VS2015, there is a new applicationhost.config file location, if you upgraded from 2012 or 2013 you will have both and 2015 won't recognize your changes – njfife Sep 23 '15 at 15:50