Hopefully someone can help with this problem. Recently our machines were updated with KB4344167 which includes security updates for .NET 4.7.1. Unfortunately this update has broken our code for a Webrequest
. When we run the code below we get this error:
The request was aborted: Could not create SSL/TLS secure channel.
// Create a request for the URL.
WebRequest request = WebRequest.Create(url);
//specify to use TLS 1.2 as default connection
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
request.Timeout = int.Parse(configmanager.GetSetting("Webtimeout"));
// Set proxy
request.Proxy = WebRequest.DefaultWebProxy;
request.Proxy.Credentials = CredentialCache.DefaultCredentials;
// Define a cache policy for this request only.
HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
request.CachePolicy = noCachePolicy;
ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, ssl) => true;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
When the security update is uninstalled from the machine the code executes fine. Are we missing something in the code above? Thats about the only thing I can think of.
Any help is greatly appreciated!
ServicePointManager.SecurityProtocol = SecurityProtocol.SystemDefault
(since 4.7), so you don't have to roll out new code as versions are introduced and deprecated. This may still cause connectivity problems to hosts if they're not up to date, but that's a problem code alone won't solve. – PedicureServicePointManager.SecurityProtocol
is accessed/copied during theCreate()
call. Changing it afterwards should have no noticeable effect (either before or after applying any fix) – Lanitalank.SystemDefault
or the KB installed? It may be that (for example) 1.3 is negotiated with the new settings, but fails on a mismatch in cipher suites. (Unfortunately TLS libs are notorious for boiling all failures down to unhelpful "it didn't work" messages.) Beyond poring over Wireshark traces, you can enable or increase the Schannel logging and see what ends up in the event log. – Pedicure