Can't see localhost from UWP app

14,059

Solution 1

It's not a bug it's a feature, called network isolation. It was introduced in Windows 8 (where Metro apps were called Windows Runtime apps).

For security reasons, a UWP app that is installed in the standard manner is not allowed to make network calls to the device it is installed on.

More details here and here.

The feature can be disabled in Visual Studio debug settings, also the article How to allow loopback for Windows Runtime apps talks about using the CheckNetIsolation Windows tool to enable loopback access per application:

CheckNetIsolation.exe LoopbackExempt -s

CheckNetIsolation.exe LoopbackExempt –a –p=S-1-15-2-4125766819-3228448775-2449327860-2490758337-1264241865-3581724871-2122349299

There are also GUI tools such as Enable Loopback Utility and Loopback Exemption Manager which make this task easier:

Enable Loopback Utility

Solution 2

It might be in the future with the project reunion .

https://github.com/microsoft/ProjectReunion/issues/113

Give your demand some emphasis in this ticket.

Share:
14,059

Related videos on Youtube

Russty
Author by

Russty

Updated on June 16, 2022

Comments

  • Russty
    Russty almost 2 years

    I’m working on UWP app on my laptop. On a previous laptop with a pre-release Windows 10, I was able to get my app to see my web API service on localhost, but on this laptop, no matter what I try, I always get this error using HTTP client:

    A connection with the server could not be established

    var response = await client.GetAsync(BuildGetRequest()).AsTask(source.Token);
    

    If I point to my published service on Azure, everything works fine. Here’s what I have tried:

    • Allowed local network loopback is set in the App’s project properties. Confirmed that my app package name is checked in the AppContainer Loopback Exemption Utility in Fiddler.
    • Set Internet (Client), Internet (Client & Server), Private Networks capabilities in Package.AppManifest
    • Tried manually setting c:>checknetisolation loopbackexempt -a -n= from the command line
    • UWP Enable local network loopback
    • Completely disabled the firewall in an act of pure desperation.
    • Run my Web API in full IIS rather than IIS Express.

    Nothing makes any difference.

    I have noticed that I’m having a similar problem in Edge, despite allowing Localhost loopback in about:flags and several other suggestions I found at:

    My Web API project runs fine in every browser except Edge, so I’m guessing as Edge is a universal app, the problem is linked. When I debug it in Edge, I get this error:

    Can’t connect to the proxy server

    If I go to Settings and switch off the manual proxy server, run it again I get:

    Hmm, we can’t reach this page

    I notice though that for some reason the Manual Proxy server setting keeps switching back on during subsequent runs.

    Could anyone suggest anything else I could try to get my UWP app to see my service on localhost?

    • grimus
      grimus about 8 years
      I'm hitting the exact same problem, even including the Edge browser not working.
    • user2431727
      user2431727 over 5 years
      Got solution for it? Me too facing same issue
  • George Birbilis
    George Birbilis over 6 years
    Problem is that even with all those you can't have a listening Socket or StreamSocket in a UWP app accepting connections from the same machine
  • Geordie
    Geordie over 6 years
    @GeorgeBirbilis arrr crap that sucks. Just found a doc here confirming this "Further, a Windows Runtime app can use an IP loopback only as the target address for a client network request." msdn.microsoft.com/en-us/windows/hh780593.aspx
  • George Birbilis
    George Birbilis over 6 years
    funny thing is that if you use the Desktop Bridge to put a Win32 app on the windows store, it will be able to do whatever it wishes regarding networking if I'm not mistaken
  • Peter Torr - MSFT
    Peter Torr - MSFT almost 6 years
    There is now an option for UWP to communicate with other apps on localhost. You still need to [remove network isolation](docs.microsoft.com/en-us/previous-versions/window‌​s/apps/… if you want to talk to a non-packaged app.
  • P_W999
    P_W999 over 5 years
    The original link to the Enable Loopback Utility doesn't work, so here's a new one: telerik-fiddler.s3.amazonaws.com/fiddler/addons/…
  • Allstar
    Allstar over 4 years
    @PeterTorr-MSFT so if you did all the above, how do you use the "uap4:LoopbackAccessRules" link you shared in your comment to allow your local server to accept your local client, say on port 21, host 127.0.0.1 ?
  • Allstar
    Allstar over 4 years
    @PeterTorr-MSFT according to this Stack post, it is impossible: stackoverflow.com/questions/54525530/…