Reputation: 3480
I have a very odd machine-specific issue. On some machines, the code below works, on others it freezes until a timeout exception is thrown on by GetResponse() call.
string url = "https://myserver/myimage.png";
System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) =>
{
return true;
});
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
req.Method = "GET";
req.AllowAutoRedirect = false;
try
{
using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
{
Console.WriteLine("Success");
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.ToString());
}
Console.ReadKey();
I can't find any OS/configuration pattern between the machines that work and the ones that fail. This is a console application running with an administrator user.
The only particular thing about this is that the URL being accessed is an image running into a test server that is using a self-issued SSL certificate, so it needed the workaround using ServerCertificateValidationCallback displayed in the code above.
Other URLs I tested worked properly.
Can anyone help me identify possible causes for this issue and workarounds?
Upvotes: 2
Views: 228
Reputation: 472
I've had the same issue on Win7 , VS2010 and it was solved by windows update - update to .NET 4.5.1
Another thing worth mentioning that it happens only in specific servers as well , not only specific clients.
(i would post as comment but not enough ratings)
Did anyone solve this without using windows update ?
Upvotes: 0
Reputation: 3480
As usual, it's quite simple once you figure it out: The machines where the problem was not present had .Net Framework 4.5 installed.
This is very likely due to the fact that 4.5 is an in-place update for 4.0, and includes several bugfixes to the core libraries.
Upvotes: 1