I am working on Blazor Server App, using .net 5 which connects to a .net framework 4 web API. When I try to connect to my hosted server which is in HTTPS, I get an error in both Visual Studio and IIS in my server. When I call an API from my Blazor Server to my Web API.
System.Net.Http.HttpRequestException: 'The SSL connection could not be established, see inner exception.'
IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
SocketException: An existing connection was forcibly closed by the remote host.
After a lot of searching, I have found no solutions
Added these lines on my Blazor Server App Startup.cs constructor.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;
Also these lines when I call the API.
HttpClientHandler clientHandler = new HttpClientHandler(); clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; }; var httpClient = new HttpClient(clientHandler);
Also executed this in my Dev PC
dotnet dev-certs https --clean
dotnet dev-certs https --trust
None of the solutions worked for me. Please help.
Note: My Web API is in HTTPS and my Blazor app is not