Have you ever wanted to test and debug a mobile ASP.NET site on an iPhone, Android phone, Blackberry, or other mobile device? If so, you might have noticed that the development server packaged up by default with Visual Studio is a little bit… limited. It doesn’t allow anyone to access your local development web server, and will actually reject requests from outside your local machine outright.
Maybe this is a good idea for security. Maybe it was a decision made to keep people from using the development servers instead of getting a real IIS server. Maybe it was just easier to program when developing Visual Studio? I am really not sure what the official reason behind it was.
First, let me ask you a few questions about mobile web development issues with ASP.NET that used to be painful for me:
- Ever had to push a site up to a development server every time you make a change?
- Tired of waiting FOREVER for sites to publish after changes just so you can test them on your device?
- Frustrated over not being able to use breakpoints after publishing to a remote server?
- Sick of resynchronizing data every time you have to push a change to your development server?
- Ever wished you could share changes from your local machine without overwriting or waiting to republish on development?
I sure hope these are things that make you mad, because they were pissing me off to no end. After doing a few full mobile sites with ASP.NET I could literally take no more. I decided to come up with a solution. Maybe it’s not the best solution, but I needed something that would solve these problems for myself and people on my teams.
I decided to go for a program that would open up the internal local port to another port of my choosing globally. All traffic is passed directly from one port to the other, internally, while being completely loss-less and unchanged. Since it’s written with the .NET framework and I generally call it like it is… I dubbed this project SharpProxy.
Using SharpProxy is easy:
- Take a peek at what port your local ASP.NET server has decided to use.
- Enter it in as the Internal Port
- Change the External Port if desired
- Hit Start
That’s it! Once you have SharpProxy up and running, you can connect your device to your internal Wi-Fi network and access the server via IP and port. In my case, the process looks like this:
- Configure and start SharpProxy
- Connect my iPhone to Wi-Fi
- Point Safari to http://192.168.1.103:5000
If I wanted to, I could setup a port forward from my router on port 5000 and use my public IP address or a dynamic DNS service. Hopefully how this all fits together is making sense – I trust you (the developer) are at least partially familiar with network scopes, firewalls and all of that.
Potential Pitfall: I really don’t think this will be a problem for most people. Still, you should be aware of it. This isn’t a problem with SharpProxy, rather it is a problem with redirections in general.
When using this with our CAS authentication server at work, I noticed that sometimes the redirects from our projects were wrong. I corrected for our case by making sure I redirect back from CAS to whatever the requested host was – NOT localhost.
In code, you can detect what the base host is by doing something like this from an ASP.NET MVC site’s controller. I think it should also work from an older ASP.NET web forms project also.
string baseURL = "http://" + this.Request.Headers["Host"];To conclude, I hope that SharpProxy can be useful for you. I’ve published the source on GitHub, so feel free to get a copy of it, or just download and use the executable (requires the .NET 2.0 framework or greater). It may work in Mono also, but I haven’t tested it.
It’s free as in beer! (That means it’s really free, no license.) If you like using it feel free to talk about, write about it, link to it, or donate a few dollars into my PayPal. I have no shame about asking for that – everybody’s gotta eat!
Download SharpProxy
(Make sure you have the .NET 2.0 framework or greater)





You are a legend. I’ll buy you a beer.
Glad you like it! It was fun to develop.
Will this work for an android phone ?
I have made a web application in asp.net , so it is possible to see the webpages created in asp.net from my android phone
Also what if I don’t have an internal Wi fi …can GPRS/EDGE be used ?
@Pankaj – Absolutely! The only thing you will have to do is forward your external port to your public IP address if you are behind a router or firewall. That should work if you are coming from 3G, EDGE, etc… Good luck!
hi..
I tried using this tool but not working in my case.When I try to test my application on Android and Blackberry simulators. It is not able to access my asp.net mvc3 application. I did the steps you mentioned above.
@Nutan – Simulators may be a special case. I’m not sure if they do NAT or not, but you may try just using the original localhost address with the weird port that .NET provides. I think a lot of simulators just share your internal address. Accessing the local server shouldn’t be a problem from there.
Pingback: asp.net, c#,javascript
Great stuff James. I’m using this to test our mobile site on Android and iPhone. Worked like a charm.
@Scott Awesome! Glad it’s working out well
Thanks very much for your excellent tool. But when i point safari to http:123.3.170.1:5000 which is my IP and port (58767), i got HTML 404 error, Can you help me with that ?
Tks again
Sorry, meant HTTP 404 error
@Tu Tran – Hmmm, getting a 404 error means that it got something at least. Try accessing the site from your local computer using the loopback at 127.0.0.1:5000 and see what happens then.
i had the same error
by the way, im using 3g broadband network, is it the reason why i get this error?
@Tu Tran – If you’re getting the same error it must be some kind of internal problem. Try stepping through your code or figuring out if you need to point it to some kind of subdirectory. Watch where it launches you to when you debug the website, then use that path off of your loopback address and port. Testing on 3G should be fine, but you will have the make sure your IP and port are both publicly accessible. That might require port forwarding.
@Tu Tran – Ah ha! Your site is clearly live, because I can see it right now
Try using this path after the port! — /PEx-Parramatta-E-Valuation/Home.aspx
Tks James, i can get it work now
sweet. This port forwarding allowed me to open my local dev server to an open port so others on the network can review. Thanks!
@Ryan – Awesome! You’re welcome!
Couldn’t you just set it up to run on IIS locally?
@Tom Absolutely! I like this a little better because it’s easy to snap into the built in dev server. It makes quick debugging easy and you don’t have to worry about redeploying after each build / reattaching the debugger. Also nice for people who might still be using XP boxes – IIS 5 loses out on wildcard extension mapping used by ASP.NET MVC.
Yet another accolade. I was so over this and I said “I bet I could write a proxy to fix this problem.” But thought first I should google, because I bet someone has.
You, sir, win the internet.
Seriously, thanks for this!
@Steven – Glad I could help! If you want to make any tweaks/improvements check out the source on GitHub
Really handy, thank you for making my life that little bit easier.
@Darcy – You’re welcome!
Really useful. Thanks!
Too easy! Cheers!
hello everyone, may i ask if what may cause if the problem is that it cannot be accessed by other network from other places, geographically speaking? i have tested it using an iphone and it worked (within same router), however, when i tried to let others look into it, it did not work. what do you think is the problem here and its corresponding solution/s? thanks
Manman – It’s likely a port forwarding / firewall problem. You’ll need to open a port on your network to allow external testing.
awesome tool, works like a charm (using it to test Jquery Mobile pages & mvc4 as framework)
I’ve already tested others port forwarding tools, that did not work well with ASP NET Development Server, but this one is great. Thanks for sharing!
Glad you like it, Eduardo!
// send login request to the webservice
String SOAP_ACTION_LOGIN = “http://tempuri.org/AuthenticateUser”;
String METHOD_NAME_LOGIN = “AuthenticateUser”;
String URL_LOGIN = “http://10.0.2.2:100/Service1.asmx?op=AuthenticateUser”;
Hi , James this is the way i am connecting using android emulator to my Web Service where host using local host ASP.NET Dev server
so
if i want to connect this service (http://localhost:100/Service1.asmx?op=AuthenticateUser ) using android real device using WI-FI what are The Steps i want to Follow
User Windows 7 , android 2.2
@Pradeep – That seems okay to me… try double checking your IP address and ports? The Android emulator’s address may be behind NAT, but I kind of doubt it.
Is this intended to work with IIS express in VS2012?
I get the following error.
Bad Request – Invalid Hostname
HTTP Error 400. The request hostname is invalid.
@Sam – I haven’t tested it with IIS express. My guess is that you will need to add another host header for your IIS site that ties to the external IP address you wish to use?
I had this problem as well with VS 2012 and IIS Express.
You can fix this problem by right clicking on your project and going to Properties > Web > Servers. Select the “Use Visual Studio Development Server” option. Keep in mind that the internal port number may change now for your project. Rerun your project, restart SharpProxy and you’re good to go!
Excellent! Great to know the old dev server is still an option. Thanks for the information.
Great application, but unfortunately its not working for me. I´m trying to access my web site from a android device, and i´m always getting an “error 400. bad request. invalid hostname”. I also created a rule in windows firewall to allow the port used by iis express, but doesn´t work.
@Adriano – Are you using IIS Express in VS 2012? Some other users have reported issues with it. I think it runs differently than the old local WebDev server.
See fix in above comment. ^^^
This is awesome. After looking for a solution for hours, YOU my friend are the Solution
Keep up the good work. Great work.
@Parag – Glad it helped!
IIS express in VS2012 does not allow proxies to connect to the development server. This project has created a workaround which seem to work: http://opensource.oxyva.nl/simple-development-proxy
yes!!!finally..its working for me..i tried opening this for web services and it also worked..
Thank you thank you veeeeeeeeeeeeeeeeery much ,i’ve been looking for this solution the whoooooooooole week end you saved my life
Awesome! Saved me an hours headache as a junior dev! Thanks man
You are a lifesaver
Very nice solution. It works perfectly!
Great little tool, good job! Have been using it for testing an ASP.NET application on iOS and Android. However, I just noticed that after some idle time I can’t access the application via a mobile device over WiFi any more (accessing the application from my PC using the external port is fine though)..I need to stop and restart SharpProxy for it to work again..wondering why it is so..thanks..
I’ve seen similar things happen in other applications but I am never sure why… Perhaps there are too many stalled TCP threads? Maybe the timeout needs to be faster or something?
Hi James, now I’m not able to connect via my smart phone at all..I start my ASP.NET development server, then SharpProxy..I load my application using the external port and my IP address on my PC which works fine…however, when I do the same using my iOS/Android device connected over the same Wifi network I get a Web page not available message…sigh
an alternative approach that is working for me at the moment: http://encosia.com/using-an-iphone-with-the-visual-studio-development-server/
If you’re using VS 2012 I have heard there is a problem with IIS Express and SharpProxy. I believe it’s related to the host headers that get configured for the site. When you come in with just the raw IP address it seems like it gets confused. I’m still on VS 2010 so I don’t have a solution for that yet, but I’m not sure you need one since it allows external connections (where the local dev server never did).
I’m actually using VS 2010..SharpProxy does work for me but it can be unreliable..having some connectivity issues with Fiddler as well so trying out Forward now: https://forwardhq.com/
Genius!