Search code examples
linkedin-apidotnetnukedotnet-httpclientdnn9

dnn give HttpClient error 'The request was aborted: Could not create SSL/TLS secure channel' on linkedin api v2 call in module


I am trying to integrate linkedin API v2 within dnn ( custome module) However when try to get token via httpclient request . It genrates error The request was aborted: Could not create SSL/TLS secure channel.

It works from mvc c# .net application but on dnn module it fails with above error. Your kind help in this regard would be highly appericiated

It works from mvc c# .net application but on dnn module it fails with above error. Your kind help in this regard would be highly appreciated. I have tried almost all solutions mentioned on stackoverflow but fail.

Using Dnn V9.3 with Framework 4.5 (4.6 also tried) DAL2 Module template. localhost with http://localhost

 public async void SaveLinkedinTok(string code, string state, string error, string error_description)
        {
            if(string.IsNullOrEmpty(code))
            {
                return View("Error");
            }

            var httpClient = new HttpClient
            {
                BaseAddress = new Uri("https://www.linkedin.com/")
            };
            var requestUrl = $"oauth/v2/accessToken?grant_type=authorization_code&code={code}&redirect_uri={AppConfig.Get("Linkedin.RedirectUrl")}&client_id={AppConfig.Get("Linkedin.ClientID")}&client_secret={AppConfig.Get("Linkedin.SecretKey")}";
            var response = await httpClient.GetAsync(requestUrl);
            var token = JsonConvert.DeserializeObject<TokenResponse>(await response.Content.ReadAsStringAsync());

System.Net.Http.HttpRequestException: 'An error occurred while sending the request Inner Exception WebException: The request was aborted: Could not create SSL/TLS secure channel.


Solution

  • Try the following:

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
    
    var httpClient = new HttpClient
    {
        BaseAddress = new Uri("https://www.linkedin.com/")
    };
    
    ...