7

Below code works fine on localhost but Getting the above error after deployed my api on microsoft azure .

My code is as follows:

public class UsersController : Controller   
{
    private readonly HttpClient _client;

    public UsersController()
    {
        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
        _client = new HttpClient { BaseAddress = new Uri("https://pincode.saratchandra.in/api") };
        _client.DefaultRequestHeaders.Accept.Clear();
        _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    }

public JsonResult GetAddress(int pincode)
{
    var response     =_client.GetAsync("/pincode/125112").Result;

    //Here it throws an exception: got no response
    if (response.IsSuccessStatusCode)
    {
    }

    return Json(ApiResult.Success(), JsonRequestBehavior.AllowGet);
}

Didn't get any response for above call just get the error

The request was aborted: Could not create SSL/TLS secure channel

3
  • Did you find a fix for this? Experiencing the same issue. Commented Oct 10, 2016 at 9:58
  • No i was not able to find a fix for it. Commented Oct 18, 2016 at 13:31
  • Are you using Azure App Services or Azure Cloud Services for your API? Commented Mar 27, 2017 at 17:00

3 Answers 3

2

We have recently had a number of similar issues with API's.

In our case these were resolved by changing the Security Protocol Type to TLS 1.2, like so:

  ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

This appears to be a result of the deprecation of SSL, and the recommendation of the adoption of TLS 1.2 by the PCI as of the middle of 2016. See here for more

EDIT:

This works for me:

 class Program
    {
        private static HttpClient _client;
        static void Main(string[] args)
        {
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
            _client = new HttpClient ();
            _client.DefaultRequestHeaders.Accept.Clear();
            _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var response = _client.GetAsync("https://pincode.saratchandra.in/api/pincode/125112").Result;
        }
    }
Sign up to request clarification or add additional context in comments.

3 Comments

i have already tried all the options for SecurityProtocol none of them not work for me -;)
For me too thats works fine on local server and windows server but on azure it doesn't work
You are not alone. There's a lengthy thread social.msdn.microsoft.com/Forums/azure/en-US/…, but no resolution
0

We have been solving the same problem just today, and all you need to do is to increase the runtime version of .NET

4.5.2 didn't work for us with the above problem, while 4.6.1 was OK

<httpRuntime targetFramework="4.6.1"/>

If you need to keep the .NET version, then set

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

Comments

0

I was facing issue with a new function app deployment, I was getting the same error message -

The request was aborted: Could not create SSL/TLS secure channel.

I was using self hosted agent but when I used Microsoft hosted agent for deployment it worked. The problem was due to some missing TLS 1.2 settings and Configuring strong cryptography. I had to add below keys in the registry and of course a machine restart afterwards.

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework\v2.0.50727]
"SystemDefaultTlsVersions" = dword:00000001
"SchUseStrongCrypto" = dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework\v4.0.30319]
"SystemDefaultTlsVersions" = dword:00000001
"SchUseStrongCrypto" = dword:00000001

And it worked as a charm afterwards. Reference

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.