Saturday, March 26, 2016

Access an IIS-hosted Site from Another PC (IIS Express + Windows Firewall)

I was working on a Intranet project for one of my client. Earlier It had to be developed with Apache web server. But later they wanted it to be developed with IIS (Internet Information Service) server. So we wanted the site i.e web application to be accessed by other PCs on the local network which's hosted on IIS Server.

Overview

This post shows the steps I used to let other PCs on the local network access a site hosted on IIS / IIS Express running on my development machine. The procedure covers:

  • Opening the server port in Windows Firewall
  • Updating the IIS/IIS Express binding (applicationhost.config)
  • Reserving the URL with netsh

Follow the steps below and replace the example port (6060) with your site’s port.

1) Confirm the site port

First you should know the port on which your site can be accessed. For example it's 6060 in my case. You can get it through WebMatrix or the IIS Manager. It looks like this in WebMatrix:

2) Open the port in Windows Firewall (Inbound rule)

Open the Control Panel -> Windows Firewall -> Advanced Settings and add a new inbound rule for the port your site is using.

Steps (high level):

  • Open Control Panel
  • Open Windows Firewall
  • Click Advanced Settings
  • Select Inbound Rules
  • Select New Rule

Choose the Port option for the rule type:

When asked for protocol/port select TCP and enter your port (6060 in my example):

Allow connections and continue:

Select the profiles to which the rule applies (Public, Private, Domain):

Save the rule with a descriptive name (for example: "IIS Site Port 6060"). That's it for opening a port.

3) Update IIS / IIS Express bindings

If you are using IIS Express (or IIS), you need to make the binding accept requests from other machines. Go to the IIS Express installation folder and open the config directory. Open applicationhost.config for edit and find the <bindings> for your site.

Add or update the binding with a line like this (use your port):

<binding protocol="http" bindingInformation=":*6060:*" />

(Or, as shown in my example — same content formatted in the original post):

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

Save the file and stop the site in IIS/WebMatrix before restarting.

4) Reserve the URL with netsh (run as Administrator)

Open an elevated command prompt (Right click -> Run as administrator) and run:

netsh http add urlacl url=http://*:6060/ user=Everyone

You can change the port to match yours. Mine is 6060 hence I mentioned 6060.

Security note

Using user=Everyone is convenient for development but broad. That grants any user the right to register and use the reserved URL namespace. For production or shared machines, prefer reserving the URL to a specific user or group. Example alternatives (replace DOMAIN\User or a local account):

netsh http add urlacl url=http://*:6060/ user="DOMAIN\User"

Always evaluate security implications before opening ports and granting broad URL reservations.

5) Restart IIS and test from another PC

Restart the IIS server (or IIS Express instance) and try to access the application from another PC on the LAN using:

http://<IP Address of the Server>:6060

Replace <IP Address of the Server> and 6060 with your server IP and port.

Quick troubleshooting checklist

  • Can you ping the server IP from the client machine?
  • Is the service listening on the expected port? (Run netstat -ano | findstr 6060 on the server.)
  • Is the inbound firewall rule enabled and targeting the correct port and profiles?
  • Confirm the binding in applicationhost.config includes the correct port and wildcard/host as needed.

That's it. Happy Coding.

No comments: