Monday, September 9, 2024

c# httpclient The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

 If we get this error while trying to get http reponse using HttpClient object, it could mean that certificate validation fails for the remote server. In this case we could get around the issue by overriding certification validation logic like so:


var handler = new HttpClientHandler

 {

     ClientCertificateOptions = ClientCertificateOption.Manual,

     ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => true

 };

 handler.AllowAutoRedirect = false;

       

 handler.ServerCertificateCustomValidationCallback = (cert, chain, erros, flag)=> { return true; };

 var apiClient = new HttpClient(handler);

 apiClient.SetBearerToken(tokenResponse.AccessToken);

 

 var response = apiClient.GetAsync(apiUrl).Result;


Wednesday, April 24, 2024

SSL Error - The connection for this site is not secure

 After cloning a git repo of dot net framework website and trying to run it all I could see was this error



Turns out the fix was to simply enable SSL in F4 properties windows and default website start url to SSL url



Monday, March 11, 2024

Visual Studio ( or VS Code) strip all attributes from html tags

 This is a very simple shortcut, find and replace using following regex

Find - <(table|tr|td|p|div|span)[\S\s]*?\n?>

Replace - <$1>

c# httpclient The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

 If we get this error while trying to get http reponse using HttpClient object, it could mean that certificate validation fails for the remo...