Tuesday, February 11, 2014

Enable Remote Requests To IIS Express

I ran into a situation where I had an issue with a web application that was isolated to the iPad running the latest OS. Using Safari's WebInspector functionality yielded nothing fruitful, so I looked to ways that I could debug the remote requests coming to my web application in visual studio.

I found a SharpProxy and IISExpressProxy, both ran, but neither worked. I stumbled upon a Hanselman blog post titled Working with SSL at Development Time is easier with IISExpress. The title wasn't very useful to my situation, however lack of other options pushed me on to reading further.

About a third of the way down there is a section called "Getting IIS Express to serve externally...". This peeked my interest and ended up being the key to what I was attempting to achieve.

The solution

Initially this did not work. I was able to run all of the commands, however I ended up having to restart Visual Studio to get the config to update.
The blog post has a bit of out dated information regarding the firewall command. Below is the command that worked for me. Run the following commands from the Developer Console in Administrator mode. Obviously you'll have to change the ComputerName and the port to your situation.
netsh http add urlacl url=http://ComputerName:58144/ user=everyone

netsh advfirewall firewall add rule name="IISExpressWeb" dir=in action=allow program="IISExpressWeb" enable=yes

"c:\Program Files (x86)\IIS Express\appcmd.exe" set site /site.name:Web1 /+bindings.[protocol='http',bindingInformation='*:58144:ComputerName']

"c:\Program Files (x86)\IIS Express\appcmd.exe" set site /site.name:Web1 /+bindings.[protocol='http',bindingInformation='*:58144:ComputerName.domain']
If the firewall line doesn't work, you may need to change the program="IISExpressWeb" to program="c:\Program Files (x86)\IIS Express\iisexpress.exe".

If you have Visual Studio open, restart it and make sure all instances of IIS Express are closed. If you don't want to run the application from Visual Studio, you can start IIS Express from the command line with (change Web1 to whatever the site name is for your web application):
"c:\Program Files (x86)\IIS Express\iisexpress.exe" /site:Web1
You should be able to access your website from your remote web browser.