1

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

  1. https://stackoverflow.com/a/67197777/835292

  2. 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;
    
  1. 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);
    
  2. 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

Taufiq Abdur Rahman
  • 1,348
  • 4
  • 24
  • 44
  • Can you access the root of the API from a browser on the computer you are running your Blazor app from? You might get an HTTP error in the browser, but that would be good. If you get a connection error, then you know it's a network problem. – Gabriel Luci Jan 11 '22 at 21:52
  • I can access the API from everywhere computers include the same computer where they are both hosted. – Taufiq Abdur Rahman Jan 12 '22 at 04:38

0 Answers0