title: Get `An existing connection was forcibly closed by remote host` when connecting to Azure Frontdoor with HttpClient
body: <p>We have some .NET code that calls Azure websites sitting behind <strong>Azure Frontdoor</strong>.  The code uses the an HttpClient to make the call in a very straightforward fashion.  We started getting the following error when calling our sites through Azure Frontdoor.  </p>
  
  <p><strong>An existing connection was forcibly closed by remote host</strong></p>
  
  <ul>
  <li>This happens with .NET Framework 4.6, .NET Framework 4.7, &amp; .NET Core 3.1.</li>
  <li>The actual Frontdoor site name doesn't matter.  Anything ending in <code>xxxx.azurefd.net</code> generates this error.</li>
  <li>The same code can hit the applications directly without issue.</li>
  <li>I can replicate this error on different Windows machines.  My laptop is running Windows 10.  We've also seen this behavior on Windows Server 2012 and other machines running Windows 10. These are corporate computers that sometimes operate behind proxies, but they still generate the error even when not behind the firewall/proxy.</li>
  <li>We've suspected that it's some type of TLS related error because Azure Frontdoor only supports TLS1.2 if you're not using a custom domain, but adding the TLS12 explicitly doesn't seem to help at all.</li>
  </ul>
  
  <p>The following code generates the problem.</p>
  
  <pre><code>static async Task Main(string[] args)
  {
      if (ServicePointManager.SecurityProtocol.HasFlag(SecurityProtocolType.Tls12) == false)
      {
          ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls12;
      }
  
      ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
      Console.WriteLine($"Protocol: {ServicePointManager.SecurityProtocol}");
  
      var client = new HttpClient { BaseAddress = new Uri("https://anything.azurefd.net") };
  
      try
      { 
          var result = await client.GetAsync("someroute");
          Console.WriteLine(await result.Content.ReadAsStringAsync());
      }
      catch(Exception e)
      {
          while(e != null)
          {
              Console.WriteLine(e.Message);
              e = e.InnerException;
          }
      }
  
      Console.ReadLine();
  }
  </code></pre>
  
  <p>Thanks in advance.</p>