Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServerCertificateCustomValidationCallback is not supported?

Tags:

c#

blazor

I am trying to make a request to a web api from Blazor WebASM project. The server hosting the web api is developer computer with self-signed certificate. I have configured CORS. I am trying with the follow code to bypass the certificate:

using( var httpClientHandler = new HttpClientHandler() )
{
    httpClientHandler.ServerCertificateCustomValidationCallback = ( message, cert, chain, errors ) => { return true; };
    using( var client = new HttpClient( httpClientHandler ) )
    {
        // Make your request...
    }
}

Anyway I am receiving the following error:

blazor.webassembly.js:1 System.PlatformNotSupportedException: Property ServerCertificateCustomValidationCallback is not supported.

  • How to make a simple http request toward a self-signed web api server from WebASM blazor project ?
like image 583
Yordan Yanakiev Avatar asked May 06 '20 21:05

Yordan Yanakiev


1 Answers

Blazor WebAssembly relies on the browser to make http requests. Under the hood, it uses the fetch api (MDN). Web browser rejects untrusted certificates for security reasons.

The solution is to add your self-signed certificate to the certificate store of the browser or operating system. You can also start your browser with specific flags to allow untrusted certificate (not recommended as it applies to all domains).

like image 178
meziantou Avatar answered Nov 02 '22 23:11

meziantou