Share via

MAUI HybridWebView working with a self signed cert for testing

Jerry Bonetti 5 Reputation points
2026-04-11T19:23:28.49+00:00

I have been trying for several days trying to get the HybridWebview to work with my a local web server running with a self signed cert and cannot get it to work.

I have tried at least 6 variations that I have found on the internet and I cannot get any of them to work.

I have tried custom web clients, custom client and handlers, and also putting a local cert in my MAUI project along with network_security_config.xml setup.

None of these have worked for me.

Does anyone know how to get this to work? I have wasted days on this. I need this to work for testing only.

I'm using NET 10

Developer technologies | .NET | .NET MAUI
0 comments No comments

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 83,741 Reputation points
    2026-04-13T18:40:40.31+00:00

    You need to define your configuration better. Are you using a real device or simulator for debug? Which o/s is hosting the device or simulator? Is the webserver the same as the simulator host? What is the certificate cname? Does the device or simulator dns server resolve the certificate cname? Are you debugging an Android or iOS app?

    0 comments No comments

  2. Nancy Vo (WICLOUD CORPORATION) 2,655 Reputation points Microsoft External Staff Moderator
    2026-04-13T03:50:33.9033333+00:00

    Hello @Jerry Bonetti ,

    Thanks for your question.

    Because your purpose is testing, I recommend these following steps:

    Wrap everything in #if DEBUG so you never ship insecure code to production.

    Step 1: Create a Custom WebViewClient (just for Android)

    Create a new file called CustomWebViewClient.cs (anywhere in your project):

    #if ANDROID
    using Android.Webkit;
    
    public class CustomWebViewClient : WebViewClient
    {
        public override void OnReceivedSslError(global::Android.Webkit.WebView view, SslErrorHandler handler, SslError error)
        {
            Debug.WriteLine("=== SSL Error bypassed for testing ===");
            handler.Proceed();
        }
    }
    #endif
    

    Step 2: Open MauiProgram.cs and add this right after builder.Services... (inside the CreateMauiApp method):

    #if ANDROID
    Microsoft.Maui.Handlers.WebViewHandler.Mapper.AppendToMapping("MyInsecureCustomization", (handler, view) =>
    {
        if (view is HybridWebView)
        {
            handler.PlatformView.SetWebViewClient(new CustomWebViewClient());
        }
    });
    #endif
    

    Step 3: For iOS, add this to your Platforms/iOS/Info.plist (inside the <dict> section):

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    

    Step 4: Test it

    1. Clean and rebuild your solution
    2. Set your HybridWebView source like this:
    hybridWebView.Source = new UrlWebViewSource
    {
        Url = "https://10.0.2.2:5001/index.html"   // ← change port as needed
    };
    
    1. Run on Android Emulator. Check the Output window (Debug tab) — you should see the message "=== SSL Error bypassed for testing ===" if the override worked.

    Note: make sure your local web server is running and reachable from the emulator.

    I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.