By default, IIS Express (via Visual Studio) will only allow connections from the local machine. This is a Good Thing but sometimes you need to test sites and services from another machine. I’ve found several guide that explain how to do this but they always seem to miss some steps. This will show how to share an IIS Express site via the host’s IP address. Using the machine name is also possible as is using the HOSTS file to fake a domain (like
api.mysite.example.com) but both of these scenarios are outside the scope of these instructions. This has only been tested on computers on the same subnet which should be sufficient for most test scenarios.
First, your project’s Web properties should look something like this:
This is the default for a new website. The port may be different and ‘Apply server settings to all users (store in project file)’ doesn’t have to be checked. The site should also run locally without issues. Make a note of the port.
HTTP.sys is a component of Windows (Vista and above) that handles HTTP requests. The url that is going to be shared needs to be reserved in HTTP.sys’s access control list (ACL). Open an administrative console. If the console doesn’t have admin rights, this won’t work. Find out your IP address and run this code to reserve the url in the ACL.
netsh http add urlacl url=http://192.168.0.6:60985/ user=everyone
You should get back this message:
URL reservation successfully added
If not, check that the console has admin rights and that the url hasn’t already been reserved in the ACL. If you need to, the reservation can be deleted:
netsh http delete urlacl url=http://192.168.0.6:60985/
Open the Windows Firewall (or whatever firewall you may have) and create an inbound rule allowing the above port (eg. 60985). Make sure it’s incoming! Yes I burned time when I accidently made it outgoing. Uncheck ‘Public’ if you don’t want the port to be open at cafes and airports.
At this point, the port should actually be available from another computer, but IIS Express will only respond to requests for
%USERPROFILE%\Documents\iisexpress\config\applicationhost.config and find the site definition for your project. The easiest way might be to search for the port as it should be unique across the IIS Express instance. Add a new binding to the site for the external facing address:
Make sure the application isn’t running and kill IIS Express:
Restart Visual Studio as administrator and relaunch the application. It should now work on an external machine. If it doesn’t work:
x.x.x.x took too long to respond) it’s probably the host’s firewall or ACL, or an unrelated network issue.