Using IIS Express to host a website (temporarily)
By default IIS Express serves only localhost requests. To serve external requests edit applicationhost.config
file (located in %userprofile%\documents\iisexpress\config\
) and change localhost
to '*'
or your machine name. (remember for non-localhost binding you must be running as administrator or set URL acl as an administrator and then run iisexpress as non-administrator)
Alternatively, you can use something like AnalogX's PortMapper to act as a small loopback proxy to tunnel privately localhost bound ports to publicly open ports.
For example,
- IISExpress is locally bound to localhost:8080
- PortMapper port 9090 is configured to relay traffic to localhost:8080
Effectively, any connection on port 9090 (opened by PortMapper) will be tunneled to localhost:8080; thereby bypassing all the netsh nonsense which can be a pain sometimes.
Below is my configuration:
The benefit of using this proxying method is that it does not permanently expose an open IISExpress port on the local dev box.
Rarely, there are times when I want to open the port publicly for meetings; but most of the time, the port should closed and only be accessible by localhost. Modifying firewall rules on the router every time is a pain. Here's how I have things setup:
- My router firewall forwards 9090 port to PortMapper
- PortMapper only continues proxying the traffic to IISExpress (listening on 8080) only if PortMapper is running.
Note
Make sure to close out all the PortMapper windows for any changes to take effect.
Note 2
As others have described, you might need to adjust the IISExpress bindings for your application in
My Documents\IISExpress\applicationhost.config
project\.vs\config\applicationhost.config
to something like:
<bindings>
<!-- bindingInformaiton format:
IPToBindTo:Port:DNSHostName -->
<!--OLD:
<binding protocol="http" bindingInformation="*:8080:localhost"/>-->
<!--Change '*' to 127.0.0.1 and remove 'localhost' right of the port number
to avoid invalid DNS hostname errors -->
<binding protocol="http" bindingInformation="127.0.0.1:8080:" />
</bindings>