Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinRT & UWP WebView localhost url doesn't fire when app is packaged

Boy I'm really struggling with this one!

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.

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.

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 Url Example ([...] = code removed):

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

Codebehind Navigating to HTML Example:

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

XAML Webview Instantiation:

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

Here are the things I've tried:

  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!

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.

like image 333
Gene Hynson Avatar asked Dec 20 '25 23:12

Gene Hynson


1 Answers

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/en-us/library/windows/apps/dn640582.aspx

like image 184
gdc Avatar answered Dec 23 '25 11:12

gdc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!