Connecting to Visual Studio debugging IIS Express server over the lan

asp.netasp.net MvcVisual Studio-2012Visual Studio-DebuggingIis Express

asp.net Problem Overview


I have a test ASP.NET MVC3 application developed in VS2012. When I start debugging the app is accessed from the host machine via the request to http://localhost:<portnumber>. But if I try to access the same application from the remote machine in the intranet via the http://<ip>:<portnumber> I get HTTP error 400: Bad request. Invalid Host Name. As far as it runs on IIS Express any server configuration is inaccessible.

Are there any ways of solving this?

asp.net Solutions


Solution 1 - asp.net

Update

I made a video that better describes the process, https://youtu.be/5ZqDuvTqQVs

If you are using Visual Studio 2013 or above, make sure you run it as an administrator for this to work.


Open the %USERPROFILE%\My Documents\IISExpress\config\applicationhost.config (in VS2015 it may be $(solutionDir)\.vs\config\applicationhost.config) file. Inside you should see something like this:

<site name="WebSite1" id="1" serverAutoStart="true">
    <application path="/">
        <virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%\WebSite1" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:8080:localhost" />
    </bindings>
</site>

Change the bindingInformation=":8080:localhost" to bindingInformation="*:8080:*" (the port number, 8080 in my case, will differ.)

Note: If it does not work try with bindingInformation="*:8080: the asterix can be removed.

Then make sure your firewall is allowing incoming connections on that port. You may need to restart the system or at least Visual Studio to get IISExpress to reload the config file.

If this doesn't work, take a look at this answer: https://stackoverflow.com/a/5186680/985284

Solution 2 - asp.net

VisualStudio 2015 Non-Admin

  1. In your solution dir, in the file .vs\config\applicationHost.config change the line

    <binding protocol="http" bindingInformation="*:44302:localhost" />

to

`<binding protocol="http" bindingInformation=":44302:" />`

(where 44302 is your port)


  1. From an admin command prompt:

    i. Enable non-admin to bind to port

    netsh http add urlacl url=http://*:44302/ user=Everyone

    ii. Allow through firewall

    netsh advfirewall firewall add rule name="IISExpress visualstudio app" protocol=tcp localport=44302 dir=in action=allow


  1. Start debugging from VisualStudio

Solution 3 - asp.net

Except to modify the iisexpress configuration file, sometimes you also need to run the command like below.

netsh http add urlacl url=http://*:49419/ user=Everyone

Solution 4 - asp.net

How to avoid running Visual Studio as an administrator

Using both Garret's and @shangkeyun's answer you can achieve connecting to the running website without needing to run Visual Studio as an admin user:

  1. Open %USERPROFILE%\My Documents\IISExpress\config\applicationhost.config

  2. Search for your site using name=MySiteName

  3. Duplicate the existing <binding> item in the <bindings> section. You should now have two lines with binding.

  4. Remove the "localhost" part in bindingInformation.

  5. It should now look like this, assuming the port is 12345:

     <binding protocol="http" bindingInformation="*:12345:localhost" />
     <binding protocol="http" bindingInformation="*:12345:" />
    
  6. Enable non-admin to bind to port

     netsh http add urlacl url=http://*:12345/ user=Everyone
    

EDIT 2019: gregmac added a step to whitelist the VS instance. I never needed this, but listing it anyway:

  1. netsh advfirewall firewall add rule name="IISExpress visualstudio app" protocol=tcp localport=12345 dir=in action=allow

Solution 5 - asp.net

Since I am unable to add a comment to @Garret Fogerlie's post and in response to the commenters' issue (@Y.Ecarri and @SamuelEdwinWard), I followed what Garret suggested, using Visual Studio 2013, running it in Admin mode and changing the application.config file.

After launching debug and seeing that I got the same error message, I went back into application.config and saw that a new entry for my site had been created just like Y.Ecarri's issue.

So I stopped debugging, kept my solution open in Visual Studio, and edited the application.config file again for the new entry. I also simply removed the * sings and localhost entirely, so I had the following for the new entry:

<binding protocol="https" bindingInformation=":44300:" />

Solution 6 - asp.net

Some of you might spend a lot of time modifying and testing using your %USERPROFILE% directory. If you are running on VS debug, use $(solutionDir).vs\config\applicationhost.config

Solution 7 - asp.net

Thanks to byteit:

Go to applicationhost.config in Documents/IISExpress/config

find the entry for the particular site you are working on:

add:

<binding protocol="http" bindingInformation="*:<your site port>:*" />

in front of the existing

 <binding protocol="http" bindingInformation="*:<your site port>:localhost" />

To achieve the solution without having VS2013 create a new website xml entry for you when you restart. You will need to run as administrator.

Solution 8 - asp.net

After the above configurations, I had to run the Visual Studio in Administrative Mode.

enter image description here

Solution 9 - asp.net

This is what worked for me:

  • Start the IIS Manager
  • Add a new virtual directory that points to the projects folder (C:\VSProjects in my case)
  • Select the new virtual directory within IIS manager. Select Directory Browsing from the list of options. On the right side there's a Enable button. Click it.

Now I can access my folder and project bin on the network through mypcname\VSProjects\myProj\outputBinViewer.

Solution 10 - asp.net

Had the a very similar issue debugging in Visual Studio Code, I solved it by adding:

"env": {
      // ...
      "ASPNETCORE_URLS": "http://*:5000" // change to the port you are using
      // ...
},

.. to launch.json

Apparently, by default it binds http protocol to 'localhost:5000', so it works with localhost but not with ip address - neither remotely nor locally.

If you are trying to hit a breakpoint by a request coming from a different computer, don't forget to check your firewall settings (and/or antivirus)

hope this helps

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiongator88View Question on Stackoverflow
Solution 1 - asp.netGarrett FogerlieView Answer on Stackoverflow
Solution 2 - asp.netgregmacView Answer on Stackoverflow
Solution 3 - asp.netshangkeyunView Answer on Stackoverflow
Solution 4 - asp.netoligofrenView Answer on Stackoverflow
Solution 5 - asp.nethvaughan3View Answer on Stackoverflow
Solution 6 - asp.netcarlo818View Answer on Stackoverflow
Solution 7 - asp.netIsaac BolingerView Answer on Stackoverflow
Solution 8 - asp.netArun Prasad E SView Answer on Stackoverflow
Solution 9 - asp.netSaiyanGirlView Answer on Stackoverflow
Solution 10 - asp.netCarlos R BalebonaView Answer on Stackoverflow