WinRT&打包应用程序后,UWP WebView本地主机URL不触发 [英] WinRT & UWP WebView localhost url doesn't fire when app is packaged

查看:69
本文介绍了WinRT&打包应用程序后,UWP WebView本地主机URL不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

男孩,我真的很挣扎!

因此,我有一个WinRT Metro应用程序,该应用程序将HTML网页嵌入到该应用程序的Web视图中.在HTML页面中,有一个div,带有指向本地主机URL的href.我正在使用此localhost调用与正在侦听localhost端口上的该URL的.NET桌面应用程序进行通信.

So I have a WinRT Metro application that has an HTML webpage embedded into a webview within the application. In the HTML page there is a div with an href to a localhost url. I'm using this localhost call to communicate with a .NET desktop application that is listening for this url on a localhost port.

当我在Visual Studio(2015年,更新1或2)中构建应用程序(作为调试或发行版)时,该应用程序将按预期工作.我可以单击div,网址被触发,并且通信成功.

When I build the application (as debug or release) in Visual Studio (2015, update 1 or 2), the application works as expected. I can click on the div, the url is fired, and the communication is successful.

但是,当我打包应用程序并将其侧面加载到我的机器上时,该功能无法正常工作.我可以单击div ...,但永远不会触发该网址.

However, when I package the application and sideload it on to my machine, the functionality does not work as expected. I can click on the div...but the url is never fired.

HTML网址示例([...] =已删除代码):

<a href="http://localhost:8123/?Api [...] >Click here</a>

导航到HTML示例的代码背后:

Codebehind Navigating to HTML Example:

this.webView.Navigate(new Uri("ms-appdata:///local/index.html"));

XAML Webview实例化:

XAML Webview Instantiation:

<WebView x:Name="webView" Grid.Row="1" ScriptNotify="webView_ScriptNotify" Grid.Column="1" Visibility="Collapsed"/>

这是我尝试过的事情:

  1. 我创建了一个WinRT应用,该应用仅包含Web视图和嵌入式HTML页面.功能在构建时有效,但在打包时无效.
  2. 我创建了一个的UWP应用,该应用包含Web视图和嵌入式HTML页面.功能在构建时有效,但在打包时无效.
  3. 我尝试按照
  1. I created a WinRT app that only contained the webview and the embedded HTML page. Functionality works when built, but not when packaged.
  2. I created a UWP app that only contained the webview and the embedded HTML page. Functionality works when built, but not when packaged.
  3. I tried packaging the app outside of Visual Studio using the command line as described here. The functionality does not work.
  4. I tried using different versions of Visual Studio 2015. Same results.
  5. I tried building/packaging on different machines. Same results.
  6. I tried to navigate to google instead of the localhost. Works.
  7. I tried to navigate to another html file instead of the localhost. Works.
  8. Naturally, I tried the obvious things too like cleaning, changing package name, changing settings in the Visual Studio App Packager, reboots, removing references, etc.

有人曾经经历过吗?打包过程似乎存在某种错误.欢迎任何建议/提示/答案!谢谢!

Has anyone experienced this before? It seems to be some sort of bug with the packaging process. Any suggestions/tips/answers are welcome! Thanks!

以防万一您想知道,此应用程序仅在我工作的公司内部供企业使用,并且不会上载到Windows应用商店.

And just in case you're wondering, this application is intended for enterprise use only within the company I work for and will not be uploaded to the Windows Store.

推荐答案

通常,您无法在UWP应用商店应用中打开回送连接.句号如果您是侧面加载或在企业环境中,则有一种解决方法:

Normally, you can't open a loopback connection in a UWP store app. Full stop. If you're side loading, or in an enterprise environment, there is a workaround:

https://msdn.microsoft.com/zh-我们/library/windows/apps/dn640582.aspx

这篇关于WinRT&amp;打包应用程序后,UWP WebView本地主机URL不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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