AppService Azure Cloud - Force TLS 1.2 outbound - C#

275 Views Asked by At

First of all, apologies if my english is not quite correct.

I'm having a problem with the TLS protocol in the Azure cloud.

When I try to make a request to an external web service of the Spanish Tax Agency, it returns the following message: The request was cancelled: A secure SSL/TLS channel could not be created.

Testing in a local environment, I solved this with the following statement: System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

But the same source code doesn't work in the Azure AppService.

How do I force the protocol for Azure?

I don't have access to a client environment, only the azure portal.

AppService - ASP.NET 4.8 FrameWork 4.5.2

Modify the value of the Web.Config targetFramework field to 4.7.2, but no changes

1

There are 1 best solutions below

1
Pravallika KV On

Thanks for the comments @jdweng

Testing in a local environment, I solved this with the following statement: System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12; But the same source code doesn't work in the Azure AppService.

To resolve this, try to upgrade TLS version of your app service manually:

Go to your Web App=>settings=>configuration=>General Settings=> Select TLS 1.2 as shown below:

enter image description here

Web.Config:

enter image description here

Note:

  • .NET Framewok 4.7 (or) later versions uses the OS settings to determine the default security protocol for SSL/TLS connections.

  • As mentioned in the official MSDOC, it is not best practice to hard code and specify TLS version in .NET framework application.

enter image description here