3Dave
3Dave

Reputation: 29081

ASP.NET The underlying connection was closed: Could not establish trust relat

When attempting to use HttpWebRequest to retrieve a page from my dev server, I get a web exception:

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel." The remote certificate is invalid according to the validation procedure...

The url I'm attempting to read from is a plain-old http://myserver.com/mypage.asp - no SSL. The production server has a valid certificate so this shouldn't be an issue, but our dev server doesn't.

Help!

Upvotes: 1

Views: 2690

Answers (3)

victorvartan
victorvartan

Reputation: 1002

Unfortunately, the link that @DavidLively provided is no longer available. You can find it using the archive of the Web: http://web.archive.org/web/20120830211353/http://blog.jameshiggs.com/2008/05/01/c-how-to-accept-an-invalid-ssl-certificate-programmatically/

Also, from that code I did this to allow any certificate, valid or not (DO NOT use this in production code!):

ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AcceptAnyCertificate);

private static bool AcceptAnyCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors)
{
    return true;
}

Upvotes: 2

robbie
robbie

Reputation: 1103

If you're having this issue even after adding the certificate to your test server's trusted root certification authorities, make sure it is added for all users not just the current user only.

More information: http://brainof-dave.blogspot.com/2008/08/remote-certificate-is-invalid-according.html

Upvotes: 1

3Dave
3Dave

Reputation: 29081

Found a good answer here:

http://blog.jameshiggs.com/2008/05/01/c-how-to-accept-an-invalid-ssl-certificate-programmatically/

Not good for production, but solves my dev server problem.

Upvotes: 1

Related Questions