0

I have created a simple modern UI app that shows the contents of the localhost site on a WebView when the app loads. The app works perfectly when I debug it. I have deployed it to another machine with Visual Studio Remote Tools and it works as expected.

However, when I publish it in the Windows store, and then install the app from there, the page is blank. The name of the app in the store is named Locked Browser Lite.

I would appreciate any suggestions.

Here's the code:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace App3
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            this.Loaded += PageLoaded;
            this.Unloaded += PageUnloaded;

            wvMain.HorizontalAlignment = HorizontalAlignment.Stretch;
            wvMain.VerticalAlignment = VerticalAlignment.Stretch;

            //wvMain.Source = new Uri("http://localhost");
        }

        private void PageUnloaded(object sender, RoutedEventArgs e)
        {
            Window.Current.SizeChanged -= Window_SizeChanged;
        }

        private void PageLoaded(object sender, RoutedEventArgs e)
        {
            Window.Current.SizeChanged += Window_SizeChanged;

            Uri targeturi = new Uri("http://localhost");
            wvMain.Navigate(targeturi);
            //wvMain.Refresh();
        }

        private void Window_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
        {
            wvMain.HorizontalAlignment = HorizontalAlignment.Stretch;
            wvMain.VerticalAlignment = VerticalAlignment.Stretch;
        }

        private void btnReload_Click(object sender, RoutedEventArgs e)
        {
            PageLoaded(sender, e);
        }
    }
}
Chi Cheung
  • 1
  • 1
  • 1

1 Answers1

0

What is the 'localhost' ??

I tried your app and yes, it's blank app .. because of your requested url, you request your app to nav to the localhost while I don't have a local server on my machine!

If you have some custom HTML page to show it to your users,try to make it available offline as an HTML file, and use webview.NavigateToString(read html from file) ..

Nasser AlNasser
  • 1,725
  • 2
  • 11
  • 12
  • I do have a web server serving a web app on localhost. It works fine if I use Internet Explorer (metro and desktop). But the app (installed thru Windows store) shows a blank page. If I deploy the app via Visual Studios Remote Tools, it works fine. I'm guessing that the Windows Store adds some sort of restriction to the app? – Chi Cheung Oct 15 '15 at 09:45
  • Yes, mostly it's because of the Store – Nasser AlNasser Oct 15 '15 at 10:40
  • Apps are sandboxed and cannot connect to localhost. However, there is this handy tool: https://loopback.codeplex.com/ – AyCe Oct 29 '15 at 08:45