从 UWP 应用程序看不到 localhost

Can#39;t see localhost from UWP app(从 UWP 应用程序看不到 localhost)
本文介绍了从 UWP 应用程序看不到 localhost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在笔记本电脑上开发 UWP 应用.在以前的带有预发布 Windows 10 的笔记本电脑上,我能够让我的应用程序在 localhost 上看到我的 Web API 服务,但是在这台笔记本电脑上,无论我尝试什么,我总是使用 HTTP 客户端收到此错误:<块引用>

无法与服务器建立连接

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

如果我指向我在 Azure 上发布的服务,一切正常.这是我尝试过的:

  • 在应用的项目属性中设置了允许的本地网络环回.确认在 Fiddler 的 AppContainer Loopback Exemption Utility 中检查了我的应用程序包名称.
  • 在 Package.AppManifest 中设置 Internet(客户端)、Internet(客户端和服务器)、专用网络功能
  • 尝试从命令行手动设置 c:>checknetisolation loopbackexempt -a -n=
  • 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:

    • https://social.technet.microsoft.com/Forums/en-US/0face535-3c7a-4658-be34-6c376322ca34/microsoft-edge-cant-open-local-domains

    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?

    解决方案

    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:

    这篇关于从 UWP 应用程序看不到 localhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)