Cannot connect to localhost in windows store application
Asked Answered
V

2

0

As I read all over the internet: Microsoft blocks the option to listen and receive traffic on localhost (127.0.0.1) for any port. I want for developing purposes to test my 2 server/client apps locally. I followed the instructions here:

But it doesn't work. When I use the Debug option I get this:

Network Capabilities Status
---------------------------------------------------------------------
    InternetClient                Not Used and Insecure
    InternetClientServer          Not Used and Insecure
    PrivateNetworkClientServer    Not Used and Insecure


Detailed Traffic Report
---------------------------------------------------------------------

    InternetClient                Not Used and Insecure

------------------------------------------------------------------


    InternetClientServer          Not Used and Insecure

------------------------------------------------------------------


    PrivateNetworkClientServer    Not Used and Insecure

------------------------------------------------------------------

Any idea why it doesn't work?

Veljkov answered 24/7, 2013 at 11:52 Comment(0)
W
9

My scenario: Developed an Windows Store App for internal use, ran fine on development machine, however when migrating to another machine any of the HttpClient calls failed. There are two issues I faced here:

  1. HttpClient failure when communicating to IIS on the local machine

  2. HttpClient failure When communicating to IIS on a remote machine on the local subnet

Problem 2 was an easy fix, in Visual Studio set the app to allow "Private Networks (Client & Server)" under the capabilities (Package.appxmanifest > Capabilities), redeploy and all is good.

Problem 1 was difficult to resolve. By default Visual Studio adds an exception in the NetIsolation which permits and denies local loopback/localhost access. You need to add your app as an exception in this list, however the information in the link provided in the OP doesn't work, I couldn't get the command to work at all, so here's how I did it:

(Note ensure the app is installed on the machine you are running this through)

  1. Go to your registry, and CTRL+F to find your app (for example if it's called TESTApp1, then enter that in to the search box).
  2. You should find a registry key that looks like a guid followed by a name, for example: ac2efce7-a15b-40d0-92db-3abde43a6778_1.0.1.15_neutral__025mzc78q1aqe

Once you have that name, in a command prompt (as administrator, just in case) run : CheckNetIsolation.exe LoopbackExempt -s

In the output, find your GUID. You will see the SID under it, make a note of this SID. 3) Run the following command, entering in your SID on the problem machine: CheckNetIsolation.exe LoopbackExempt -a -p=SIDHERE

Note: Alternative step 2: You can also find your SID under the following registry key (assuming you have installed the app):

HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppContainer\Mappings

Again, CTRL+F and find your app under there.

Wish answered 17/1, 2014 at 17:52 Comment(2)
Do you know if this still works under windows anniversary update? Is the isolation exemption exactly the same in both directions, or will it allow outgoing connections (from UWP to localhost) while blocking incoming connections (localhost to UWP)? Since the anniversary update this doesn't seem to work for me.Integration
Thanks. This also works on newer Win10 versions. You can also use CheckNetIsolation.exe LoopbackExempt -a -n=AppContainerName instead of the SID.Undesigning
D
1

The easiest solution I found was to let Fiddler set up the loopback exceptions for me. You can download Fiddler for free. Once Installed, follow this guide for choosing which apps to grant exceptions for. Remember to also complete the steps regarding the certificate if you are planning to use HTTPS. I hope that helps others save some time.

Danzig answered 3/7, 2015 at 6:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.