43

After debugging my website in Visual Studio 2015, I can visit it via localhost:50544. I would like to visit my website on a different computer from which it is being served upon that is also on the same network. To do this I should be able to visit that computers address which is 192.168.1.13:50544.

However when visiting this address I get a 'Bad request, invalid host name' error. Even if I visit it on the same machine as the website is being served on.

Following the advice here I have created the following windows firewall rule and have also tried turning the firewall off entirely. picture of firewall rule

I'm using IIS express and so have added to the '~\Documents\IISExpress\config\applicationhost.config' file

<binding protocol="http" bindingInformation=":8080:localhost" /> //original rule
<binding protocol="http" bindingInformation="*:50544:192.168.1.13" />

But visiting 192.168.1.13:50544 on any machine still results in the 'Bad Request' error.

RADXack
  • 1,032
  • 3
  • 11
  • 17
  • 7
    Also noteworthy is that there are many applicationhost.config files. I were editing the file located in `%USERPROFILE%\Documents\IISExpress\config` when you actually edit the one in `ProjectName\.vs\config` – RADXack Feb 08 '16 at 16:12

7 Answers7

44

You have to run Visual Studio as Administrator

In Visual Studio 2015 the applicationhost.config is located it the folder in the project itself. Esc MyProjectName\.vs\config, note that the .vs folder may be hidden. Change the Ip from there, not IISExpress folder.

Your <binding protocol="http" bindingInformation="*:50544:192.168.1.13" /> is correct.

Seagull
  • 1,063
  • 1
  • 11
  • 18
  • 18
    Run as Admin is key here! – jharr100 Feb 24 '17 at 18:29
  • 1
    Didn't work for me. Windows 10, VS15, IIS Express serving https (may that be the problem?). Following instructions. Run as Administrator ecc... Changing the IIS config results in it be automatically overwritten by adding an entire new section "site name='mywebsite(x)'. with 'x' as a progressive int and with old "localhost" address any time I start the website. Modifying from VS15 (website properties) web > project url: "192.168.0.2:44324/"; results in "Unable to launch the IIS Express web server". – Luke Apr 25 '17 at 12:10
  • Not work ... https://s17.postimg.org/43uuusdrz/chrome_2017-05-22_22-17-20.png help me. – Matheus Miranda May 23 '17 at 01:53
  • @MatheusMiranda You have to use Internet Information Services (IIS) Manager instead. [link] (https://i-technet.sec.s-msft.com/dynimg/IC396222.jpg) – Seagull May 23 '17 at 07:08
  • @Chaika - this answer is wrong. See my updated answer which explains why this works, but is the incorrect solution. – Kev May 23 '17 at 13:49
32

The format of the bindingInformation attribute is:

ip address:port:host header

What you need is:

bindingInformation="192.168.1.13:50544:*"

Source: https://www.iis.net/configreference/system.applicationhost/sites/site/bindings/binding?showTreeNavigation=true#006

Update:

There appear to be some folks who are under the mistaken belief that this answer is incorrect. First of all go read the documentation (see link above) and read the examples.

Secondly IIS and IIS Express are essentially the same product. IIS Express has been tweaked so that non-administrators can run IIS on developer PC's where they might not have full local admin rights. Despite this, both IIS and IIS Express use the same applicationHost.config file formats, and this means that the bindingInformation attribute format is exactly the same for both products.

The reason that the (incorrect) :50544:192.168.1.13 bindingInformation string works is because (rightly or wrongly):

  • if there is no host header specified

  • if there is no matching IP address in the first part of the binding info field

... then IIS will try to match to an IP address in the host header part of the binding info string.

The correct format for both IIS7+ and IIS Express is, and always has been:

ip_address:port:host_header
Alireza
  • 10,237
  • 6
  • 43
  • 59
Kev
  • 118,037
  • 53
  • 300
  • 385
  • 2
    This is not true for VS 2015 / IIS10. is correct. – Luke Apr 25 '17 at 12:12
  • @Luke I would beg to differ. The format is and always has been `ip_address:port:host_header`. Just checked my own IIS Express and Full Fat IIS, See also: https://www.iis.net/configreference/system.applicationhost/sites/site/bindings/binding?showTreeNavigation=true#006 – Kev Apr 25 '17 at 14:38
  • Why do you think it's different on your machine? – Kev Apr 25 '17 at 14:39
  • 1
    @Luke - please see my update to this answer which explains why `*:50544:192.168.1.13` happens to work, but is wrong. – Kev May 23 '17 at 13:50
  • Please have a look at official Microsoft documentation: https://msdn.microsoft.com/en-us/library/microsoft.web.administration.binding.bindinginformation(v=vs.90).aspx – Luke May 23 '17 at 14:35
  • Also note whenever I try to write bindingInformation your way, it is automatically DELETED and REWRITTEN. – Luke May 23 '17 at 14:36
  • @Luke - how are you doing this - via the MWA API? Editing applicationhost directly? via the binding manager in IIS Manager MMC? I looked at that documentation link, it's exactly as I described in my answer: `ip:port:host`. – Kev May 23 '17 at 14:45
  • OK, now I read back and understand what you mean. It's passed a long time and I am not really that much more into it. So, it is upside down, the system is automatically rewriting my applicationhost bindingInformation to "port:ip" format, no matter how I write it. – Luke May 23 '17 at 14:57
  • @Luke - sounds like you were missing either a leading or trailing `:`. What did you use to set the binding info string? – Kev May 23 '17 at 15:09
  • Sorry mate, I don't remember it was 2 months ago. It is not that important. I just remarked my different personal experience in that circumstance. Have a nice day! – Luke May 23 '17 at 15:13
  • 1
    Thanks a lot @Kev was struggling with this a lot. your answer sloved it. – Newton Sheikh May 28 '18 at 07:22
  • In my case, adding :* made VS crash, but it works if I delete the colon and asterisk at the end. – Running Buffalo Jan 10 '20 at 17:31
  • VS2019: changing the existing binding for localhost port 2916 worked with `` – Adam May 24 '20 at 01:06
10

We made an extension called Conveyor that you can use to open up IIS Express to external access without any config changes.

https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti

Jim W
  • 4,866
  • 1
  • 27
  • 43
4

In case someone is still having issues with this, the thing that fixed it for me is running Visual Studio in administrator mode.

I've read somewhere that IIS will not let you use anything else than localhost as the host if not in that mode (after editing the config file I was getting error that IIS could not be started)

Also very important as stated by OP, edit the file in your project (%PROJECT%\.vs\%PROJECT%\config\applicationhost.config), not the one in the IIS Express folder...

Ry-
  • 218,210
  • 55
  • 464
  • 476
0

I had same issue with remote access and I tried all of these tips to fix it. For me helped ticking "Allow anonymous authentication" in Web project config.

0

I had everything working fine until today.

  • firewall ok
  • VS runs in admin mode
  • applicationhost.config file ok

I just disabled "Enable Edit and continue" (in csproj) and it stopped working. I enabled it again, and there we go again.

Hope this helps

Daniel
  • 9,312
  • 3
  • 48
  • 48
0

This solution helped me with .net 6 aspNetCore app.

Find a file Properties\launchSettings.json

Go to iisSettings->iisExpress->applicationUrl

I replaced my http://localhost:51222/ to http://192.168.1.126:51222/

"iisExpress": {
  "applicationUrl": "http://192.168.1.126:51222/",
  "sslPort": 44392
}
rnofenko
  • 9,198
  • 2
  • 46
  • 56