Carlos Coelho
Carlos Coelho

Reputation: 586

TLS error when calling an Azure Function with "HTTPS Only" activated

I have an ASP.NET application that makes calls to an Azure Function. Everything works fine if the Function setting HTTP Only is off, although when I turn it on the application fails to call the Function with the following error:

Exception:
System.AggregateException: One or more errors occurred.
---> System.Net.Http.HttpRequestException: An error occurred while sending the request.
---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send.
---> 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: An existing connection was forcibly closed by the remote host

The Function configs are:

enter image description here .

The application is running on .net framework 4.6.1. Follows the code that calls the Function:

client = new HttpClient
{
    BaseAddress = new Uri("https://myfunction.azurewebsites.net/")
};

client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

var request = new Email(to, from, subject, body);

var response = client.PostAsync("/api/SendEmail", request, ClientUtil.GetJsonMediaType()).Result;

I don't want to set ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls12;

Upvotes: 0

Views: 1247

Answers (1)

Carlos Coelho
Carlos Coelho

Reputation: 586

I've given up and just forced the code with tls12 instruction. :(

Upvotes: 1

Related Questions