23

I am using VS2012 with IIS Express and can not seem to browse my web sites using my IP Address. Is there some way to do that? It used to work fine with earlier versions of VS.

For example, this address works fine:

http://localhost:64651/

But, this address does not work.

http://192.168.252.165:64651/

I am sure of the IP Address, since I just got it using ipconfig.

John Saunders
  • 157,405
  • 24
  • 229
  • 388
ADH
  • 2,502
  • 5
  • 25
  • 50

2 Answers2

32

Go to your IISExpress>Config folder, locate applicationhost.config. Change <bindings> as below:

<bindings>
      <binding protocol="http" bindingInformation="*:1407:YOUR_IP_ADDRESS" />
</bindings>

Before you do this , you will have to register this IP address using netsh command as below:

Port forwarding in Windows 7

If you’re running Windows 7, pretty much all incoming connections are locked down, so you need to specifically allow incoming connections to your application. First, start an administrative command prompt. Second, run these commands, replacing 192.168.1.11:1234 with whatever IP and port you are using:

> netsh http add urlacl url=http://192.168.1.11:1234/ user=everyone

This just tells http.sys that it’s ok to talk to this url.

IMPORTANT: The user=everyone parameter must be specified according to the system language. So if your windows language is spanish the parameter must be user=todos.

> netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=1234 profile=private remoteip=localsubnet action=allow

This adds a rule in the Windows Firewall, allowing incoming connections to port 58938 for computers on your local subnet.More information at this link.

Port forwarding Mac OS X

Step 1: View Current Firewall Rules

sudo ipfw show

Step 2: Add Port Forwarding Rule (80 to 8080)

The default port that Tomcat runs on is 8080, so here we show the command to do port fowarding from port 80 to 8080 (Tomcat’s default port). Obviously, this works for other ports as well, and you’d just have to adjust the command accordingly.

sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to any 80 in

This is a temporary change, and it will revert once you reboot. If you want to make it permanent, you can create a lauch deamon for it.

Optional Remove Rule

If you want to remove your firewall rules run:

sudo ipfw flush

Port Forwarding Using PFCTL (aka PF) on Mac OS X

The setup for pfctl is similar to ipfw. Github user kujon has created a nice guide to show how to set up port forwarding from port 80 to another port using pfctl.

Note: Be sure to change the bindings of your project only by locating its name. You can even keep the localhost binding and add a new one , this way you can access same webpage using both the given IP address and your old localhost binding.

Bhushan Firake
  • 8,928
  • 5
  • 39
  • 75
  • Thank you for your response. I am on Windows 7 Enterprise. How do I register the IP Address using netsh? – ADH Feb 14 '13 at 18:36
  • Okay, I can view the web page with both localhost and my ip address from my machine. But, and maybe I should have mentioned this in the first place, my iPod Touch, which is connected to the same wireless network, cannot see the web page. The whole point is that I am trying to build a web site for mobile devices and deploying to a remote server is taking too long between testing the changes. – ADH Feb 14 '13 at 19:00
  • I marked the answer as resolved. I also verified the firewall Inbound Rule is added. Tried another machine on the network also, but still cannot see the web page even though I can ping from there to my local machine. – ADH Feb 14 '13 at 19:08
  • @AllanHorwitz The machines you are trying to access the website on , should ne under the same private network. It has an IP address of C class . That is, in the form of 192.168.[0-255].[0-255] – Bhushan Firake Feb 14 '13 at 19:11
  • 1
    Had to change the rule to apply to the Domain. Works great now. Thanks again. – ADH Feb 14 '13 at 19:17
  • N.B. If you are running a localized version of Windows the parameter `users=everyone` for `netsh` (second step) may cause error 1789. Solution is to translate `everyone` to the corresponding group name in your language. – mflodin Aug 21 '13 at 13:47
  • @BhushanFirake I have tried your solution but it only works for few seconds and then for some reason my visual studio gives this error `Unable to lunch IIS express web server` I have opened a new question regarding that error: [the question's link](http://stackoverflow.com/questions/19074767/accessing-localhost-from-another-pc-and-getting-unable-to-lunch-iis-express-web) – Poorya Oct 02 '13 at 13:28
  • 2
    Where is this folder? (IISExpress>Config) I am running it on VS2010 and can't find this. Update: It is here: C:\Program Files (x86)\IIS Express\config\templates\PersonalWebServer – Rodney Oct 29 '13 at 21:43
  • 1
    @Rodney The folder is at this location: `C:\Users\{UserNAme}\Documents\IISExpress\config`. Preferably documents directory of your system drive. – Bhushan Firake Oct 30 '13 at 05:34
  • You should add that path to your answer. I'm downvoting bc applicationhost.config is a large file and you don't specify where the bindings element goes. You also don't explain what this mysterious `1407` is, and you use a different port other than the one the OP is using. – toddmo Jul 27 '17 at 01:32
  • @bhushan, I am using windows 10 with visual studio 2017, I tried this solution but can't able to run my solution in IP address, its showing service unavailable and same time localhost is working fine. Could you help Me? – Raja Nov 11 '17 at 05:10
  • @Raja Hey, sorry, I haven't been able to get my hands on VS2017 yet. But the process should be similar. Make sure you fired the commands in administrator mode i.e. by starting command prompt in admin mode. – Bhushan Firake Nov 11 '17 at 11:46
  • @BhushanFirake Hi, i'm a little confused between all the port numbers in your answer: 1407 in the binding and 1234 in the command, should they be different? and is 1407 corresponds to my application's port number? – mshwf Jun 12 '18 at 09:39
-1

You can use Conveyor by Keyoti

Step 1:

Download the Visual Studio Extension by searching for 'Conveyor' in the Tools->Extensions and Updates dialog.

Step 2:

Conveyor is automatically enabled for web application projects, run (debug) a project and note the Remote URL, that is the URL you will use from your device or other computer. Please see troubleshooting below if you don't see the Conveyor window.

Conveyor screenshot

Step 3:

Add an inbound firewall rule allowing access to the TCP port given in the Remote URL.

1. Open Windows 'Start' and type WF.msc.
2. Click 'Inbound Rules' on the left.
3. Click 'New Rules' on the right.
4. Choose 'Port' in the new dialog, then 'Next'.
5. Select TCP, and enter the port from the Remote URL next to 'Specific local ports' (probably 45455), then 'Next'.
6. Next, and next (you may want to disable 'Public'), give it a name like 'Conveyor: web dev server access enabled'.

Step 4:

Use the Remote URL from your device (phone, tablet or other machine) to directly access your application.

More information at Conveyor

Daniel
  • 33
  • 7