Articles in this section
Category / Section

How to resolve the "Could not create SSL/TLS secured channel" error when running dashboard embedded application?

Published:

An error "Could not create SSL/TLS secure channel" arises occasionally while executing the ASP.NET application when a client is unable to establish a secure connection with a server using the SSL or TLS protocol. 


Steps to resolve the error "Could not create SSL/TLS secure channel":

    1. In the embedded application, open the file HomeController.cs, navigate to the GetToken() method, and add the below setting.
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;

Here is the code snippet of GetToken method with the above line added.

public Token GetToken()         {             using (var client = new HttpClient())             {                 System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;                 client.BaseAddress = new Uri(EmbedProperties.RootUrl);                 client.DefaultRequestHeaders.Accept.Clear();                 var content = new FormUrlEncodedContent(new[]                 {
                    new KeyValuePair<string, string>("grant_type", "embed_secret"),                     new KeyValuePair<string, string>("Username", EmbedProperties.UserEmail),                     new KeyValuePair<string, string>("embed_secret", EmbedProperties.EmbedSecret)                 });                 var result = client.PostAsync(EmbedProperties.RootUrl + "/api/" + EmbedProperties.SiteIdentifier + "/token", content).Result;                 string resultContent = result.Content.ReadAsStringAsync().Result;                 var response = JsonConvert.DeserializeObject<Token>(resultContent);                 return response;             }         }
    2. Now, build and run the ASP.NET MVC embedded application to render the dashboard.

Related Links





Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
SM
Written by Soundarya Mani Meharan
Updated:
Comments (0)
Please  to leave a comment
Access denied
Access denied