0
votes

In my local PC development environment, I have a dotnetcore 2.2 project running in port 5000 as https and 5001 as http. I need to use https in my develop environment. From my PC I can enter via https://localhost:5000/ without any error (VS install a localhost SSL certificate). Using my PC IP https://192.168.0.2:5000 the browser launch an SSL certificate error (the SSL certificate is for localhost). I'm developing a Xamarin.Forms 4.5.0.396 for Android (9.0API level 28) and iOS, and I'm using standard WebView control.

In Android, when I navigate (webView.Source) to http://192.168.0.2:5001, it works, but when I try https://192.168.0.2:5000, the webView remains in blank. No Exceptions but Navigated event launched. I try several ways like exposed in:

ClientCertRequestHandler is unknow and don't know the assembly to reference

Also, I know that is not the solution, but I implemented a custom renderer (https://docs.microsoft.com/es-es/xamarin/xamarin-forms/app-fundamentals/custom-renderer/hybridwebview) to try to override SSL validation method, but it not works.

Any suggestion?

1
Please verify if you 192.168.0.2:5000 works on a browser in you local network. To verify if you Android webview is set up correctly use any known https url like gmail.com or stackoverflow.com and see if that works in your web view. This in not a solution but it will help you find you culprit. - Piyush Priyadarshi
I tested with https:// stackoverflow.com/ and works. I tested in Android browser https:// 192.168.0.2:5000 and the browser shows an SLL error. In WebView the screen remains blank, not show the SSL error and the Navigated event is fired normally. - Duefectu
Can you tell if the same url works in chrome or any other browser in Android device? - shanranm
As I tell to @Piyush in his answer I tested;"I tested with https:// stackoverflow.com/ and works. I tested in Android browser https:// 192.168.0.2:5000 and the browser shows an SLL error. In WebView the screen remains blank, not show the SSL error and the Navigated event is fired normally." - Duefectu

1 Answers

0
votes

The solution is to overryde the OnReceivedSslError method on the JavaScript WebClient class, like this:

    public class JavascriptWebViewClient : WebViewClient
{
    string _javascript;

    public JavascriptWebViewClient(string javascript)
    {
        _javascript = javascript;
    }

    public override void OnReceivedSslError(Android.Webkit.WebView view, SslErrorHandler handler, Android.Net.Http.SslError error)
    {
        //base.OnReceivedSslError(view, handler, error);
        handler.Proceed();
    }

    public override void OnPageFinished(Android.Webkit.WebView view, string url)
    {
        base.OnPageFinished(view, url);
        view.EvaluateJavascript(_javascript, null);
    }
}

The problem is that adding the OnReceivedSllError I have two MAX_PATH erros... Don't know why, but rebuilding or cleaning the solution didn't works.

I cleaned the solution several times, moved closest to the root folder. Clean and Rebuild without run, then run works for me, but no breakpoint stop on this method.

It's a really very extrange behaviour on Xamarin.Forms 4.5.0.396, but after update to Xamarin.Forms 4.5.0.495 it works and stop at breakpoint