none
[WPSL]How to identify the WebBrowser.NavigationFailed error code? RRS feed

  • Question

  • Hi,

    I am developing application for Windows Store and Windows Phone Silverlight. I have requirement to show the WebBrowser.NavigationFailed reason.

    It can be directly available in store WebView(WebViewNavigationFailedEventArgs). but I can't see the way to detect in Silverlight. Please suggest me.

    Thanks,


    Pallam Madhukar Windows Phone Developer


    Thursday, December 8, 2016 6:37 AM

All replies

  • Hi Pallam Madhukar,

    Since your problem more related to Windows Store and Windows Phone Silverlight development, I help you move this thread to UWP forum to get a better help. Thanks for your understanding.

    Best Regards,
    Weiwei


    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.

    Friday, December 9, 2016 3:23 AM
  • Hello Pallam,

    In WPSL, this is also available from this event:

    https://msdn.microsoft.com/en-us/library/windows/apps/microsoft.phone.controls.webbrowser.navigationfailed(v=vs.105).aspx

     <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                <phone:WebBrowser HorizontalAlignment="Left" IsScriptEnabled="True" Margin="23,31,0,0" VerticalAlignment="Top" Height="499" Width="404" NavigationFailed="WebBrowser_NavigationFailed"/>
    
            </Grid>

    In code behind:

     private void WebBrowser_NavigationFailed(object sender, NavigationFailedEventArgs e)
            {
                var error = e.Exception.HResult;
            }

    Best regards,

    Barry


    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.


    • Edited by Barry Wang Friday, December 9, 2016 6:10 AM
    Friday, December 9, 2016 6:09 AM
  • Hi Barry,

    I have tried your code. I am getting e.Exception=null. Please help me to find a way here.

    Thanks,


    Pallam Madhukar Windows Phone Developer

    Friday, December 9, 2016 9:22 AM
  • @Pallam,

    Can you show me more details about how I can reproduce your issue? For example, how to reproduce the WebBrowser_NavigationFailed event?

    And you can also manually debug your code to see the values from your "e", this pointer will show you some info when you debug your code. Maybe it contains the info you need. 

    Best regards,

    Barry


    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.

    Friday, December 9, 2016 9:27 AM
  • Hi Barry,

    Please download the sample here. I didn't see any error information. the exception is always coming as null.

    Thanks,


    Pallam Madhukar Windows Phone Developer

    Friday, December 9, 2016 10:36 AM
  • @Pallam,

    Thanks for your detailed sample. Now I can understand what happened and what you want.

    Actually I've test on WinRT and I find the following:

    There are only URI and WebErrorStatus in WebViewNavigationFailedEventArgs.

    However in WPSL there are more:

    Personally I think what we meet is not a exception so the Exception null is alright. (Since you are navigate to a error URL, it should not be a exception).

    So if we want to get the error message we may do something like this:

     HttpWebRequest request = WebRequest.Create(new Uri("http://dummy.example")) as HttpWebRequest;          
                request.Method = "HEAD";       
                try
                {
                    var test = await request.GetResponseAsync();              
                }
                catch(Exception ex)
                {
                    var errorcode = ex.HResult;
                    var exceptioninfo = ex.Message.ToString();
                }

    Do you think this is reasonable for you?

    Best regards,

    Barry


    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.

    Wednesday, December 14, 2016 10:29 AM