从UWP应用中看不到localhost [英] Can't see localhost from UWP app

查看:182
本文介绍了从UWP应用中看不到localhost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

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

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

  • 在应用程序的项目属性中设置了允许的本地网络环回. 确认已在Fiddler的AppContainer环回豁免实用程序中检查了我的应用程序包名称.
  • 在Package.AppManifest中设置Internet(客户端),Internet(客户端和服务器),专用网络功能
  • 尝试从命令行手动设置c:> checknetisolation loopbackexempt -a -n =
  • UWP启用本地网络环回
  • 完全绝望地完全禁用了防火墙.
  • 在完整的IIS(而不是IIS Express)中运行我的Web API.
  • 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.

没有任何区别.

我注意到我在Edge中也遇到了类似的问题,尽管允许about:flags中的Localhost环回以及我在以下位置找到的其他一些建议:

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:

我的Web API项目在Edge以外的所有浏览器中都能正常运行,所以我猜想,因为Edge是通用应用程序,因此问题是相互联系的.当我在Edge中调试它时,出现此错误:

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

如果我转到Settings并关闭手动代理服务器,请再次运行它,我得到:

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.

有人可以建议我尝试获取UWP应用来在本地主机上查看我的服务吗?

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

推荐答案

这不是bug,它是一种功能,称为网络隔离.它是在Windows 8(Metro应用称为Windows Runtime应用)中引入的.

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).

出于安全原因,标准中安装了UWP应用 不允许以这种方式对设备进行网络呼叫 安装在.

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.

更多详细信息此处可以在Visual Studio调试设置以及文章

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

还有GUI工具,例如 启用回送实用程序 Loopback免税管理器可使此任务更容易:

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆