Access ASP.NET Core 2.1 web app hosted on localhost from mobile device

In most cases, all you will have to do is replace "localhost" with a wildcard * (or with your local LAN IPv4 Address) in Properties/launchSettings.json:

{
  // ...
  "profiles": {
    // ...
    "Moshoboga": {
      // ...
      // replace: "applicationUrl": "https://localhost:5001;http://localhost:5000"
      "applicationUrl": "https://*:5001;http://*:5000"
    }
  }
}

Then navigate to your local ip in any browser on your LAN. Find this with ipconfig on Windows, or ifconfig on Unix/Linux


I use this, maybe it can help

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseUrls("https://*:5566")
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>();

Note that for the latest .Net, you set the URLs in the launchSettings.json file as shown below:

latest .Net version

Make sure to enable the port 5566 in firewall. From the phone access https://your_comp_ip_address:5566/ it should work. Change your_comp_ip_address to your computer ip address, you can check it from the CMD. Just run 'ipconfig' in the CMD

From Visual Studio, run the App itself, not IIS Express, select AppNamefrom the drop down, then press F5. Kindly Check all of these photos below:

From The Drop Down, select the AppName to run it

Windows Firewall Ports, add a new Outbound Rule: Port, say give a range of 5560-5570

Check the IP address

Make sure when you run, a CMD is displayed, and check out the code https://*:5566

From your phone browser, enter the url correctly

And then, voila!!! Your Web App is running


localhost always points to the current device loopback address, so localhost on your pc points to itself and localhost on a phone points to itself as well. If your phone is connected to the same network as your pc you could launch the site on a specific local ip address instead of localhost and connect using the ipaddress. But I don't think it is possible to use IISExpress with anything other than localhost. You could use a different launch profile and just use kestrel directly with an ipaddress instead of using IISExpress.

If you use an android emulator on your machine then you could access the site via a special ipaddress that allows the emulator to connect to the pc, so if running at localhost:5566, from the emulator you would use http://10.0.2.2:5566

I'm not sure about other emulators for iphone etc, they may have different conventions.