title: The SSL connection could not be established between WebApp and WebApi (Asp Core 3.1)
body: <p>I wrote an ASP.NET Core 3.1 MVC web application. It's an front end calling a Web API back end.</p>
  
  <p>The application works perfectly on development and Staging.</p>
  
  <p>I can't make it work on Production: the Web API seems ok, I can call it from the browser or Postman.</p>
  
  <p>But I can't reach it from my web app. This is the error from the log when it tries to make a call:</p>
  
  <blockquote>
    <p>info: System.Net.Http.HttpClient.IApiClient.ClientHandler[100]<br>
    Sending HTTP request GET <a href="https://webapi" rel="nofollow noreferrer">https://webapi</a>.****.it/inetApi/api/links</p>
    
    <p>fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]  </p>
    
    <p>An unhandled exception has occurred while executing the request.</p>
    
    <p>System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.</p>
    
    <p>System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..</p>
    
    <p>System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.</p>
    
    <p>--- End of inner exception stack trace ---</p>
  </blockquote>
  
  <p>Staging and Production are both Windows server 2019 machines with IIS10 web server.</p>
  
  <p>Staging has a single website where both the Web API and the web app run as applications: </p>
  
  <pre><code>Web-t.****.it/inetApi
  Web-t.****.it/inetW
  </code></pre>
  
  <p>Production VM has two website, one is supposed to be for internal web apps and the other for APIs: </p>
  
  <pre><code>webapi.****.it/inetApi
  intranet.****.it/inetW
  </code></pre>
  
  <p>We made this VM from the scratch, it's new, there aren't any other application or websites on it.</p>
  
  <p>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.</p>
  
  <p>I tried to force the web app to use TLS as security protocol using this in my startup.cs:</p>
  
  <pre><code>ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
  </code></pre>
  
  <p>But it only change the error:</p>
  
  <blockquote>
    <p>info: System.Net.Http.HttpClient.IApiClient.ClientHandler[100]<br>
    Sending HTTP request GET <a href="https://webapi" rel="nofollow noreferrer">https://webapi</a>.****.it/inetApi/api/links</p>
    
    <p>fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]</p>
    
    <p>An unhandled exception has occurred while executing the request.</p>
    
    <p>System.Net.Http.HttpRequestException: An error occurred while sending the request.</p>
    
    <p>System.Net.Http.WinHttpException (80072EFF, 12030): Error 12030 calling WINHTTP_CALLBACK_STATUS_REQUEST_ERROR, 'The connection with the server was terminated abnormally'.</p>
    
    <p>at System.Threading.Tasks.RendezvousAwaitable`1.GetResult()<br>
    at System.Net.Http.WinHttpHandler.StartRequestAsync(WinHttpRequestState state)<br>
    --- End of inner exception stack trace ---</p>
  </blockquote>
  
  <p>So I tried to call the production Web API from the web app on staging or development, and it works.</p>
  
  <p>Then I tried to use the web app on Production with the staging Web API... and it works too!</p>
  
  <p>This is driving me nuts.</p>
  
  <p>It's like everything in production is working individually, but not together.</p>
  
  <p>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.</p>
  
  <p>Any ideas?</p>