16

Objective

I'm looking for the simplest-possible, step-by-step setup process for debugging my ASP.NET MVC 4 application using my IP address as the URL. I want to be able to access the application from my Android phone, which is connected to my local network via Wi-Fi, using my computer's local IP address (e.g. - http://192.168.1.109:25968). I'm running Visual Studio 2012 RC on Windows 7.

This question has been addressed by two other questions (this one, and this one), but the answers are extremely brief and aren't helping me at all. I've had to resolve this issue before by banging on my computer and mindlessly changing every setting until something worked. I don't want to have to go through that again. I want to understand what I'm doing this time.

Setup Information

The project is just a default ASP.NET MVC 4 Internet Application. I'm pretty sure I haven't changed anything yet.

The Web tab in my application's Properties is set to "Use Local IIS Web Server", and I have "Use IIS Express" checked. The Project url is http://localhost:25968/. I see that the "locahost" there might be a problem, but VS won't let me put in an IP address or wild cards.

My IIS Express applicationhost.config file for my application are as follows.

<site name="APPLICATION_NAME" id="13">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Users\USERNAME\Documents\Visual Studio 11\Projects\APPLICATION_NAME" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:25968:localhost" />
    </bindings>
</site>

What's Happening

When I connect to the site from the host computer with http://localhost:25968 it works great. If I try to use http://192.168.1.109:25968 from the host computer, I get "Bad Request - Invalid Hostname, HTTP Error 400. The request hostname is invalid." Using this same URL from another computer on the network, it just times out.

Community
  • 1
  • 1
Logical Fallacy
  • 3,017
  • 5
  • 25
  • 41

4 Answers4

21

Grant yourself permission to bind to both localhost and wildcard network adapters, configure IIS Express to bind to them, and open the port on your firewall. By using a wildcard, you don't have to reconfigure when your IP address changes.

Step details: (they assume a port number of 5555 - use your actual port instead)

  1. Run these commands from a command prompt as Administrator:

    netsh http add urlacl url=http://localhost:5555/ user="NT AUTHORITY\INTERACTIVE"
    netsh http add urlacl url=http://*:5555/ user="NT AUTHORITY\INTERACTIVE"
    
  2. In .vs\config\applicationhost.config (or for pre-VS2015, %USERPROFILE%\Documents\IISExpress\config\applicationhost.config), add a wildcard binding to your site. The result should look like this:

    <site name="..." id="...">
        <!-- application settings omitted for brevity -->
        <bindings>
            <binding protocol="http" bindingInformation="*:5555:localhost" />
            <binding protocol="http" bindingInformation="*:5555:*" />
        </bindings>
    </site>
    
  3. Open the firewall port for your IIS Express site. You can do this from an administrative command prompt:

    netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=5555 profile=private remoteip=localsubnet action=allow
    
Edward Brey
  • 40,302
  • 20
  • 199
  • 253
  • I think your answer is the best, but would you elaborate on #3 so this answer is most useful to others for reference? Would you run the #3 that I stated in my answer? – Logical Fallacy Apr 22 '14 at 21:35
  • @David: I haven't needed to dig into firewall details yet, so I don't know the answer. I mostly use the emulator. My time using a physical phone talking to IIS on my dev computer has been brief enough that I've "opened the port" by just temporarily turning off the firewall. – Edward Brey Apr 23 '14 at 02:45
  • fair enough. The information is here anyway. I regret not accepting your answer earlier. This question has received quite a number of views, and I think your answer is best. Thanks again. – Logical Fallacy Apr 23 '14 at 03:17
  • @David: I'm a fan of one-stop shopping on Stack Overflow, so since you're `netsh` command works nicely, I incorporated it into my answer. – Edward Brey Apr 23 '14 at 12:20
  • Thanks ! i was trying all the answers from SO and this is the only one that worked for me ! Galaxy S3 , Windows 7 and IIS express. – user636525 Oct 30 '14 at 02:15
  • Used this setup to test on VS2015 RC, Windows 7 and Android. Worked perfectly just pay close attention to the port numbers, I had the binding all set up correctly and had a typo in my firewall rule port # which prevented the site from loading... – matt. Jun 27 '15 at 18:25
  • 1
    after doing this, I get "unable to connect to web server 'IIS Express'". Any solution for this? – Chris Oct 06 '20 at 11:47
5

Give this a shot:

netsh http add urlacl url=http://192.168.1.109:25968/ user=everyone

From: http://johan.driessen.se/posts/Accessing-an-IIS-Express-site-from-a-remote-computer

You might be able to substitute your computer's hostname for the IP address so you don't have to re-run that every time your IP changes.

cfeduke
  • 23,100
  • 10
  • 61
  • 65
  • Now entering http://192.168.1.109:25968/ is giving me "Service Unavailable -- HTTP Error 503." on my computer, and when I try to access the link from another computer on the network the connection just times out. – Logical Fallacy Nov 11 '12 at 02:49
  • See if there is a detailed explanation in the Event Log for that PC, specifically for HTTP.SYS. It could be a permissions thing, even as ridiculous as not ever permitting everyone to access IIS Express. – cfeduke Nov 11 '12 at 02:53
  • ... and check for previous reservations, or remove the reservation with `netsh http delete url=http://192.168.1.109:25968` (from http://haacked.com/archive/2007/05/21/the-iis-7-team-rocks.aspx) – cfeduke Nov 11 '12 at 02:55
  • Running `netsh http delete urlacl url=http://192.168.1.109:25968/` gets me back to HTTP error 400. (note the addition of 'urlacl'). – Logical Fallacy Nov 11 '12 at 03:06
  • This looks like exactly the solution to your problem: http://johan.driessen.se/posts/Accessing-an-IIS-Express-site-from-a-remote-computer – cfeduke Nov 11 '12 at 03:14
  • I don't see anything in the logs other than the netsh commands I just ran. – Logical Fallacy Nov 11 '12 at 03:15
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/19388/discussion-between-david-englund-and-cfeduke) – Logical Fallacy Nov 11 '12 at 03:21
  • Also encountered 503 error, solved by changing localhost to computer name in applicationhost.config `bindingInformation="*:5555:MYPCNAME"` –  Apr 21 '16 at 07:02
1

I needed to perform all of the steps from the link that cfeduke provided. (Not just the one he describes in his answer.)

  1. Add <binding protocol="http" bindingInformation="*:58938:192.168.1.42" /> to applicationhost.config after the binding for 'localhost'.
  2. Run netsh http add urlacl url=http://192.168.1.42:58938/ user=everyone
  3. Run netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=58938 profile=private remoteip=localsubnet action=allow
Logical Fallacy
  • 3,017
  • 5
  • 25
  • 41
0

If you got Node.js on your machine Try this tool by: Ionut-Cristian Florescu

https://github.com/icflorescu/iisexpress-proxy

To install it just write on the command line npm install -g iisexpress-proxy

Then check the port that you have in your project and map it to outer port. iisexpress-proxy [localPort] to [proxyPort]

xsoh
  • 419
  • 3
  • 11