Friday, March 27, 2015

Exposing IIS Express On The Internet From Visual Studio 2013

Exposing IIS Express on the Internet

I'm working on a project that will be a subscription paid service. Naturally, I'm going with PayPal because, well, what else would you use? They're everywhere. I'm going simple with payment buttons,
but I do need to know subscription, account, and payment status in order to properly deal with accounts. It seems the most simple way to deal with this is to set up an IPN so that when account events happen the site is notified and it responds appropriately. The problem is that there really are only two ways to debug this thing.
1) Create an elaborate logging system, write code, publish the application, and review the logs.
2) Expose your development environment on the Internet, and simply step through the code like a normal person.

I decided to go with number 2, but as with everything out there on the Internet, not only is the devil in the details, but nearly without fail, some of those devilish details are missing. 
After fighting with this for a bit, all the pieces finally fell in to place. I thought I'd put them out here to see if someone else might benefit from what I was able to figure out.   

Putting it together


I'm assuming that you've configured port forwarding on your router, and your project is configured to run under IIS Express rather than the Visual Studio development web server. 

Step 1 - Update binding information in applicationhost.config

Open Documents/IISExpress/config/applicationhost.config under your user profile in windows and look for the <bindings> section. It should look similar to:
     <binding protocol="http" bindingInformation="*:48965:localhost" />  
Add a new line similar to the following:
 <binding protocol="http" bindingInformation="*:48965:" />  
Replace the port with the port on which IIS Express is hosting your application.
If you've configured port forwarding to forward to an IP address, put the IP address of your local machine in place of the above IP address. If you've configured port forwarding to resolve to a host name, replace the IP address with the name of your local machine, and save the file.

Step 2 - Allow incoming connections to IIS Express

Open the command prompt with admin privileges and run the following (replacing the port and IP address as appropriate) 
 netsh http add urlacl url= user=everyone  

Step 3 - Allow connections through the firewall

Create a rule allowing incoming connections on the port that IIS Express is using to host your application. 
Me, I went the lazy route and shut off the firewall during debugging sessions. That works as well. 
Anyway, on to futzing with PayPal tomorrow.