UPDATE: See [here] for an updated version of this post addressing Windows 7 issues.
One of the things that makes working with and debugging ASP.NET so easy is the ASP.NET Development server. With the ASP.NET Dev Server you can test and debug your ASP.NET code in Visual Studio by simply pressing <F5>.
As you know, when debugging ASP.NET code on your desktop, the desktop browser accesses your ASP.NET development site using a localhost URL referencing the specific port for the ASP.NET Development Server instance. Something like this…
If you have an iPhone or iPod Touch (or Windows Mobile or BlackBerry device) on your local Wi-Fi network, it would seem reasonable that you should be able to access your development site by using the same URL with the localhost part changed to your desktop computer’s IP Address or name. Assuming that the desktop IP Address is 22.214.171.124, the URL would look like this...
Unfortunately, you’ll find that your device’s browser will report that the site cannot be reached.
Interestingly, if you were to enter that same URL into a Windows Mobile emulator or BlackBerry simulator running on your desktop it’ll work just fine. So what’s the problem??
The issue is that for security reasons, the ASP.NET Dev Server will not accept connections issued by other computers. Your desktop browser and the emulators/simulators are able to access your site because they are processes executing on your local desktop, the same computer on which the ASP.NET Dev Server is running.
So what’s the solution? … Make the ASP.NET Dev Server think that the connection from your device is actually occurring on the local desktop.
This is easily done using any kind of port-forwarding software. This is software running on your desktop that accepts HTTP connections on one port and then forwards everything received on that port to another port.
There are any number of applications that do this sort’a thing. The one I use is a really (really) old tool I’ve used for years from the Microsoft Soap Toolkit 3.0 simply called “Trace Utility”. You can download the toolkit from here. If you already have a networking tool that supports port forwarding, I’d go ahead use that instead.
If you do decide to use the Soap Toolkit Trace Utility one thing you’ll want to remember when installing the toolkit is to only install the “Debugging Utilities”. The rest of the components in the toolkit are used for COM-based Soap development which isn’t relevant to what we’re doing.
In the case of the Soap Toolkit Trace Utility, all you need to do to enable port forwarding is
- Start the utility
- Select File | Formatted Trace
- It will then prompt you for the port to listen on, and the machine and port to forward to.
- The listen port defaults to 8080 which in most cases you can leave as is.
- The destination host defaults to localhost which you'll also want to leave as is
- For the destination port, enter the port number of the ASP.NET Dev server
- In the above examples, the ASP.NET Dev Server port is 3804.
- Click OK.
With that, you now have port-forwarding in place. Now on your device, enter the URL using the Trace Utility listen port, 8080, like this.
You’ll find that your iPhone, iPod Touch, Windows Mobile, or BlackBerry device will now be able to access your dev site just fine.
This all works very simply … the device is connecting to the utility and the utility is connecting to the ASP.NET Dev Server. Because the utility is running on your desktop, the ASP.NET Dev Server is happy to accept the connection.
I’ve been using this technique for a number of years (as you can tell by the utility I use) and it continues to work very well. I hope you find it as useful as I have.
Sep 03 2009, 09:32 AM