129

Is it possible to use IIS Express to host pages on a network. Out of the box it can do localhost but I am trying to bind it to an IP address.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
jdiaz
  • 7,354
  • 12
  • 42
  • 51
  • 1
    You can do it without config changes with our extension (Conveyor) https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti – Jim W Jul 05 '18 at 22:26
  • 1
    @JimW, Yours is the best response IMO, worked quickly and seamlessly. Thanks! You should make yours answer. – Vman Dec 17 '18 at 11:38

5 Answers5

126

I think you can.

To do this you need to edit applicationhost.config file manually (edit bindingInformation '<ip-address>:<port>:<host-name>')

To start iisexpress, you need administrator privileges

Community
  • 1
  • 1
vikomall
  • 17,379
  • 6
  • 49
  • 39
  • 3
    that was it. Copied the applicationhost.config and modified the binding to – jdiaz Feb 02 '11 at 22:08
  • 1
    Do you know if you can set it up to listen to "Any IP"? – Alxandr Jun 01 '11 at 14:11
  • 3
    I have same problem. I changed the binding information as per your suggestion and re-started the iis express. When i launched my web projects from Visual Studio, its still going to http://localhost:yyyy./xxxx. Any ideas? – palm snow Jan 03 '12 at 20:48
  • 37
    This information is great: thank you. I learned the hard way that to open IIS to external traffic (not localhost) you need to be running as Administrator. (I was testing a tablet on my LAN). If you're working from Visual Studio run it as Administrator so the access extends to its sub-processes. This will open up IISExpress to bind to something other than localhost. ` ` – Daniel B. Chapman Feb 04 '13 at 15:40
  • 24
    Note To Self : If you get Access Denied, **Run Visual Studio as Admin**. – nVentimiglia Oct 15 '13 at 00:13
  • 1
    Use the answer below by `@Anthony Ludmilin` and just remove localhost and leave it blank. If you use computername it won't launch when Visual Studio goes to localhost:xxxx – user3885927 Jun 03 '15 at 20:51
  • 37
    UPDATE FOR VISUAL STUDIO 2015: In Visual Studio 2015 the IIS Express configuration files have moved. They are now separate per project, and stored in /{project folder}/.vs/config/applicationhost.config http://johan.driessen.se/posts/Accessing-an-IIS-Express-site-from-a-remote-computer – Shane Castle Feb 06 '16 at 05:00
  • I am curious as to why you have insisted on IIS Express. I am not trying to judge anyone, but I have always jumped right to local IIS, then stage, prod. I feel like that level of control gives you so much more than IIS Express, especially when the port number being used is constantly changing. As best I can tell, it seems to be a way to not have another variable in your SDLC that could defer dates, but if there is this much trouble just to get it established, is it worth it? Or is there something very major that I am missing? – Anthony Mason Feb 14 '16 at 13:03
  • 2
    FYI in agreement with @ShaneCastle, to find my applicationhost.config file, I click the system tray arrow to find the IIS Express tray icon, right click and 'Show All Applications', mine was running as a single entry in the list. Left clicking the Application Name field shows an extra info panel in the same dialog with the path to the applicationhost.config .. left clicking the config file path opened it in VS for editing. – Neek Feb 28 '17 at 07:26
  • Sharing for future reference. The answer is correct, however... If you do not have admin privileges in your network, you get access denied error even if you run VS as admin. – apollo Sep 26 '17 at 13:54
  • Admin priviledges are not strictly required. As an admin you can grant the desired privilege to the yourself (`netsh http add urlacl url=http://:/ user=everyone`), and it will then work from non-UAC VS. See https://learn.microsoft.com/en-us/iis/extensions/using-iis-express/handling-url-binding-failures-in-iis-express – Remus Rusanu Sep 13 '19 at 09:08
  • 8
    UPDATE FOR VISUAL STUDIO 2017 TO 2019: The files have been moved from `/{project folder}/.vs/config/applicationhost.config` to `/{project folder}/.vs/{solution name}/config/applicationhost.config`. I ran into the problem of supporting two versions of vs and forgot to modify the right config – TabsNotSpaces Oct 31 '19 at 18:20
  • I know this post is old as dirt, but can someone who's knowledgeable about this update the answer to be more specific? Is `ip-address` the IP we want to use as the URL? Is `port` the local/incoming port? Is `host-name` the machine that its running on? When are they optional? – Hill Dec 03 '19 at 21:50
  • %userprofile%\Documents\IISExpress\config folder or %userprofile%\My Documents\IISExpress\config folder, depending on your OS. When you run a site from a configuration file, you can specify which site to run. – mirazimi Jun 14 '21 at 09:27
106

In order for IIS Express answer on any IP address, just leave the address blank, i.e:

bindingInformation=":8080:"

Don't forget to restart the IIS express before the changes can take place.

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
Anthony Ludmilin
  • 1,061
  • 1
  • 7
  • 2
  • 35
    IIS Express must run as Administrator to bind to anything but `localhost`. If launching from `VS 2010`, run `VS 2010` as Administrator. – Eric J. Apr 19 '12 at 21:42
  • 2
    I tried doing this - but when i go to http://192.168.1.10:55870/ it automatically redirects me to http://localhost/ – merk Sep 21 '12 at 20:33
  • 5
    Note To Self : If you get Access Denied, **Run Visual Studio as Admin**. – nVentimiglia Oct 15 '13 at 00:14
  • Always says Bad Request if I access on anything other than localhost:8080 – Jack Mar 16 '14 at 03:47
  • @Jack So did I until I heeded Eric's advice above. – Luke Puplett Apr 17 '14 at 12:14
  • Also, I had an issue where several different profiles were created in applicationhost.config for my site. It caused IISExpress to crash often, and take forever to startup. Once I cleared all but one it fixed. – Jack Apr 17 '14 at 13:38
  • 3
    Just to add to those who might suffer like me for 3 hours, there are many `bindinginformation` attributes in the `applicationhost.conifg` file, choose the one that belong to your site! – Ghasan غسان May 23 '14 at 00:16
  • 7
    Make sure to run Visual Studio as Administrator and set `bindingInformation=":8080:"` not `bindingInformation="*:8080:*"` to stop Visual Studio from writing a new `` entry after restarting Visual Studio – Tod Thomson Feb 11 '15 at 01:13
  • This worked for me with https as well - – DotNetWala Aug 02 '15 at 22:50
  • This one worked for me (vote for marking as solution) `bindingInformation=":8080:"` binds perfectly to any ip-address. `` kept raising "issexpress creation of virtual directory failed". – pellekrogholt Jun 08 '16 at 08:45
  • 4
    This workaround did the trick for me `bindingInformation=":8080:"`. For some reason `*8080*` wasn't working for .NET Core Web apps. Don't forget to run `netsh: netsh http add urlacl url=http://*:8080/ user=\Everyone` to avoid running VS as admin and also add a firewall rule for this port in your Windows Firewall or the app that manages firewall settings. – Daniel Bogdan Jan 24 '18 at 09:41
46

As mentioned above, edit the application host.config. An easy way to find this is run your site in VS using IIS Express. Right click the systray icon, show all applications. Choose your site, and then click on the config link at the bottom to open it.

I'd suggest adding another binding entry, and leave the initial localhost one there. This additional binding will appear in the IIS Express systray as a separate application under the site.

To avoid having to run VS as admin (lots of good reasons not to run as admin), add a netsh rule as follows (obviously replacing the IP and port with your values) - you'll need an admin cmd.exe for this, it only needs to be run once:

netsh http add urlacl url=http://192.168.1.121:51652/ user=\Everyone

netsh can add rules like url=http://+:51652/ but I failed to get this to place nicely with IIS Express. You can use netsh http show urlacl to list existing rules, and they can be deleted with netsh http delete urlacl url=blah.

Further info: http://msdn.microsoft.com/en-us/library/ms733768.aspx

Dave Glassborow
  • 3,253
  • 1
  • 30
  • 25
16

Below are the complete changes I needed to make to run my x64 bit IIS application using IIS Express, so that it was accessible to a remote host:

iisexpress /config:"C:\Users\test-user\Documents\IISExpress\config\applicationhost.config" /site:MyWebSite
Starting IIS Express ...
Successfully registered URL "http://192.168.2.133:8080/" for site "MyWebSite" application "/"
Registration completed for site "MyWebSite"
IIS Express is running.
Enter 'Q' to stop IIS Express

The configuration file (applicationhost.config) had a section added as follows:

<sites>
  <site name="MyWebsite" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
      <virtualDirectory path="/" physicalPath="C:\build\trunk\MyWebsite" />
    </application>
    <bindings>
      <binding protocol="http" bindingInformation=":8080:192.168.2.133" />
    </bindings>
  </site>

The 64 bit version of the .NET framework can be enabled as follows:

<globalModules>
    <!--
        <add name="ManagedEngine" image="%windir%\Microsoft.NET\Framework\v2.0.50727\webengine.dll" preCondition="integratedMode,runtimeVersionv2.0,bitness32" />
        <add name="ManagedEngineV4.0_32bit" image="%windir%\Microsoft.NET\Framework\v4.0.30319\webengine4.dll" preCondition="integratedMode,runtimeVersionv4.0,bitness32" />
    -->             
    <add name="ManagedEngine64" image="%windir%\Microsoft.NET\Framework64\v4.0.30319\webengine4.dll" preCondition="integratedMode,runtimeVersionv4.0,bitness64" />
Thomas Bratt
  • 48,038
  • 36
  • 121
  • 139
  • Great detailed answer. Wish I could upvote +50. I appreciate that you had the paths in there for applicationHost.config and all details. Thanks. – raddevus Jun 14 '15 at 18:52
10

Change bindingInformation=":8080:"

And remember to turn off the firewall for IISExpress

Liam
  • 27,717
  • 28
  • 128
  • 190
Ha Doan
  • 611
  • 6
  • 20