How To Access Localhost ASP.NET Webapp from Mobile/Tablet Device

In this post, we will show you step by step on how to access a localhost ASP.NET Web application from your mobile/tablet device. This is really necessary when we need to test whether or not the functionality of our web app works on a mobile device.

For example, your localhost web app address is http://localhost:50751. And you want to access this app on your mobile device via LAN IP address, http://192.168.0.105:50751

To do this, let’s follow the following steps:

 

1. Turn off Windows Firewall

We fristly need to turn of Windows Firewall as below screenshot.

 

2. Get your LAN IP Address

Run ipconfig command into your Command Prompt. In the below screenshot, my LAN IPv4 Address is 192.168.0.105.

 

3. Add Inbound Rule of Windows Firewall

  • Open the Windows Firewall with Advanced Security
  • Create a new Inbound Rule

  • Rule Type: select Port

  • Protocol and Ports: select TCP and specific your local ports. In the below screenshot, Port of my asp.net web app is 50751

  • Action: select Allow the connection

  • Profile: check all Domain, Private and Public

  • Name: set your rule name

 

4. Add Bindings of IIS Manager or IIS Express (Visual Studio)

There are the following two cases:

  • If you are running the app in Visual Studio, follow “4.1. Add Bindings of IIS (Visual Studio)” section.
  • If you are running the app in IIS, follow “4.2. Add Bindings of IIS Manager” section.

4.1. Add Bindings of IIS Express (Visual Studio)

  • Open applicationhost.config file
    • If you are using Visual Studio 2015+, this file is located at <Your Solution Name>\.vs\config\applicationhost.config‌
    • If you are using the previous version of Visual Studio 2015, this file is located at C:\Users\<Your Profile Name>\Documents\IISExpress\config\applicationhost.config
  • In applicationhost.config , search by the port number of your web app, then add new binding with your LAN IP address
<site name="my-webapp" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="D:\Projects\my-webapp" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:50751:localhost" />
        <binding protocol="http" bindingInformation="*:50751:192.168.0.105" />
    </bindings>
</site>

In the above, we added this new binding:

<binding protocol="http" bindingInformation="*:50751:192.168.0.105" />

 

4.2. Add Bindings of IIS Manager

  • Open IIS Manager
  • At the left side, select Sites > Default Web Sites
  • At the right side, select Bindings…
  • Add a new Site binding with your LAN IP address and port

 

5. Run the Web application on Mobile device

You can now run the web app on your mobile device. If you are running the web app in Visual Studio, you should close and run it as administrator (Right-click on Visual Studio > Run as Administrator).

 

Leave a Reply

avatar