none
WebView returns 404 instead of local page RRS feed

  • Question

  • I need to embed a web browser in my desktop application. I am replacing the old COM WebBrowser with the new WebView component. It works great going to any external website I've tried. However, I need to reach an internal website. When I try this I get 404 - NotFound. My website never sees the request.

    I've tried setting IsPrivateNetworkClientServerCapabilityEnabled=true but that causes the exception: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Microsoft.Toolkit.Win32.UI.Controls.DesignerUI.resources" was correctly embedded or linked into assembly "Microsoft.Toolkit.Forms.UI.Controls.WebView" at compile time, or that all the satellite assemblies required are loadable and fully signed.'

    How can I enable access to internal websites using WebView?

    Wednesday, September 11, 2019 10:56 PM

All replies

  • Hi,

    Please provide your code ,I found a link that has similar errors to you.

    https://stackoverflow.com/questions/55497936/wpf-webview-doesnt-show

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 12, 2019 5:27 AM
    Moderator
  • Does it work if you move the IsPrivateNetworkClientServerCapabilityEnabled line to another place, such as the constructor of the user control or form, after InitializeComponent( )?

    Thursday, September 12, 2019 11:47 AM
  • Yes, I've tried a few places in the code and the result is always the exception.
    Thursday, September 12, 2019 1:31 PM
  • My Web Browser Test program is for Windows Forms. Here is the code (sans designer):

    using System;
    using System.Text.RegularExpressions;
    using System.Windows.Forms;
    using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;
    // ReSharper disable LocalizableElement
    
    namespace BrowserTestForm
    {
        public partial class WebViewTest : Form
        {
            public WebViewTest()
            {
                InitializeComponent();
    
                webView.NavigationCompleted += WebViewOnFrameNavigationCompleted;
                webView.NavigationStarting += WebViewOnFrameNavigationStarting;
                webView.NewWindowRequested += WebViewOnNewWindowRequested;
    
                // webView.IsPrivateNetworkClientServerCapabilityEnabled = true;    // This lines causes the exception below
                //    System.Resources.MissingManifestResourceException
                //        HResult=0x80131532
                //        Message=Could not find any resources appropriate for the specified culture or the neutral culture.
                //        Make sure "Microsoft.Toolkit.Win32.UI.Controls.DesignerUI.resources" was correctly embedded or linked into assembly
                //        "Microsoft.Toolkit.Forms.UI.Controls.WebView" at compile time, or that all the satellite assemblies required are loadable and fully signed.
            }
    
            private void WebViewTestLoad(object sender, EventArgs e)
            {
                webView.Navigate( Constants.DefaultNavigationTarget );
            }
    
            private void ButtonGoClick(object sender, EventArgs e)
            {
                NavigateTo( textBoxAddress.Text );
            }
    
            private void ButtonBackClick(object sender, EventArgs e)
            {
                if ( webView.CanGoBack ) webView.GoBack();
            }
    
            private void ButtonForwardClick(object sender, EventArgs e)
            {
                if ( webView.CanGoForward ) webView.GoForward();
            }
    
            private void TextBoxAddressKeyUp(object sender, KeyEventArgs e)
            {
                if ( e.KeyCode == Keys.Enter )
                {
                    e.Handled = true;
                    NavigateTo( textBoxAddress.Text );
                }
            }
    
            private void TextBoxAddressEnter(object sender, EventArgs e)
            {
                textBoxAddress.SelectAll();
            }
    
            private void NavigateTo( string url )
            {
                if ( !url.StartsWith( "http" ) ) url = "http://" + url;
                webView.Navigate( url );
            }
    
            private void WebViewOnFrameNavigationStarting( object sender, WebViewControlNavigationStartingEventArgs e )
            {
                if (e.Uri != null)
                    textBoxAddress.Text = e.Uri.AbsoluteUri;
            }
    
            private void WebViewOnFrameNavigationCompleted( object sender, WebViewControlNavigationCompletedEventArgs e )
            {
                if (!e.IsSuccess)
                {
                    var num = (int) e.WebErrorStatus;
                    var msg = Regex.Replace( e.WebErrorStatus.ToString(), "([A-Z])", " $1" ).Trim();
                    webView.NavigateToString( $"<html><body><h1>{num} - {msg}</h1></body></html>" );
                }
            }
    
            private void WebViewOnNewWindowRequested( object sender, WebViewControlNewWindowRequestedEventArgs e )
            {
                // stay in same window/tab
                NavigateTo( e.Uri.AbsoluteUri );
            }
        }
    }
    
    Thursday, September 12, 2019 1:33 PM
  • Hi,

    Do  you use webview to return the error in winform program,not wpf?

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 19, 2019 9:42 AM
    Moderator