Fabio Maccari
Fabio Maccari

Reputation: 57

The SSL connection could not be established between WebApp and WebApi (Asp Core 3.1)

I wrote an ASP.NET Core 3.1 MVC web application. It's an front end calling a Web API back end.

The application works perfectly on development and Staging.

I can't make it work on Production: the Web API seems ok, I can call it from the browser or Postman.

But I can't reach it from my web app. This is the error from the log when it tries to make a call:

info: System.Net.Http.HttpClient.IApiClient.ClientHandler[100]
Sending HTTP request GET https://webapi.****.it/inetApi/api/links

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]

An unhandled exception has occurred while executing the request.

System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.

System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..

System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.

--- End of inner exception stack trace ---

Staging and Production are both Windows server 2019 machines with IIS10 web server.

Staging has a single website where both the Web API and the web app run as applications:

Web-t.****.it/inetApi
Web-t.****.it/inetW

Production VM has two website, one is supposed to be for internal web apps and the other for APIs:

webapi.****.it/inetApi
intranet.****.it/inetW

We made this VM from the scratch, it's new, there aren't any other application or websites on it.

I already tried to move the Web API application into the same website of the web app to see if that could be the problem, but it doesn't.

I tried to force the web app to use TLS as security protocol using this in my startup.cs:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

But it only change the error:

info: System.Net.Http.HttpClient.IApiClient.ClientHandler[100]
Sending HTTP request GET https://webapi.****.it/inetApi/api/links

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]

An unhandled exception has occurred while executing the request.

System.Net.Http.HttpRequestException: An error occurred while sending the request.

System.Net.Http.WinHttpException (80072EFF, 12030): Error 12030 calling WINHTTP_CALLBACK_STATUS_REQUEST_ERROR, 'The connection with the server was terminated abnormally'.

at System.Threading.Tasks.RendezvousAwaitable`1.GetResult()
at System.Net.Http.WinHttpHandler.StartRequestAsync(WinHttpRequestState state)
--- End of inner exception stack trace ---

So I tried to call the production Web API from the web app on staging or development, and it works.

Then I tried to use the web app on Production with the staging Web API... and it works too!

This is driving me nuts.

It's like everything in production is working individually, but not together.

I have grants to do everything I need on the VMs... but I'm a developer (and not very good at dealing with systems), and I can't ask much help to the sysadmins because they are overwhelmed in this period.

Any ideas?

Upvotes: 1

Views: 26509

Answers (1)

Abraham Qian
Abraham Qian

Reputation: 7522

According to the Transport security Best practice, as much as possible not to specify the SSL version during the establishment of SSL connection. Just let the OS decide on the SSL protocol version.
https://learn.microsoft.com/en-us/dotnet/framework/network-programming/tls
There might be something wrong with the validation process of the SSL certificate installed on the server-side. As you know, SSL communication requires the trust relationship between the client-side and the server-side, therefore I would like to know how you specify the certificate for your WebAPI project. have you established the trust relationship between the client-side and the server-side? namely, install the service certificate on the client-side. As to explain how it works properly in the development and Staging environment, Http Get request doesn't represent something, please try an Http Post request.
Besides, the SSL protocol requires the DotNet framework/OS support, try to install a high version DotNet framework.
Feel free to let me know if you get something new afterward.

Upvotes: 2

Related Questions