0

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://learn.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?

Duefectu
  • 1,563
  • 4
  • 18
  • 37
  • Can you tell if the same url works in chrome or any other browser in Android device? – memsranga Mar 24 '20 at 12:08
  • 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 Mar 24 '20 at 12:23
  • Seems like a duplicate of - https://stackoverflow.com/questions/7416096/android-webview-not-loading-an-https-url – memsranga Mar 24 '20 at 15:26
  • The post https://stackoverflow.com/questions/7416096/android-webview-not-loading-an-https-url has 8 years!!! The things changed a little! And the question is not for Xamarin.Forms – Duefectu Mar 24 '20 at 15:56
  • 1
    Please verify if you https://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 https://gmail.com or https://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 Mar 19 '20 at 18:19
  • 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 Mar 20 '20 at 08:12
  • 1
    https://stackoverflow.com/questions/49280982/webview-in-my-app-is-not-loading-an-https-url https://stackoverflow.com/questions/45869184/android-webview-load-https-url-results-in-blank-screen – Fox Mar 30 '20 at 22:14
  • Hi, did you solved the issue? – Anand Mar 31 '20 at 06:55
  • It's a very strange behaviour. I don't found any post about Xamarin.Forms, all of it are about Xamarin.Android and has 2 or 3 years old, and didn't solve the problem, but it helped me to found a solution. I post as Answer to explain and comment it. – Duefectu Mar 31 '20 at 07:43

1 Answers1

0

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

Duefectu
  • 1,563
  • 4
  • 18
  • 37