Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Could not establish trust relationship for the SSL/TLS secure channel
WhatsApp
Manish Dwivedi
14y
10.3
k
0
1
25
Blog
"Could not establish trust relationship for the SSL/TLS secure channel "
That problem comes when you try to call https webservices in your web application. for solving this problem:
1. you need to install server certificate.
2. Alternate method is create static class which always validate to server certificate and returns true
you can do this by using this code:
using
System
.
Net
;
using
System
.
Net
.
Security
;
using
System
.
Security
.
Cryptography
.
X509Certificates
;
public
static
class
WebConnect
{
/// <summary>
/// Sets the cert policy.
/// </summary>
public
static
void
SetCertificatePolicy
(
)
{
ServicePointManager.
ServerCertificateValidationCallback
+= RemoteCertificateValidate;
}
/// <summary>
/// Remotes the certificate validate.
/// </summary>
private
static
bool
RemoteCertificateValidate
(
object
sender, X509Certificate cert,
X509Chain chain, SslPolicyErrors error
)
{
// trust any certificate!!!
return
true
;
}
}
before making connection to service, use SetCertificatePolicy method and your problem resolved.
Up Next
WCF Service does not have a Binding with the None MessageVersion
Ebook Download
View all
Printing in C# Made Easy
Read by 22.3k people
Download Now!
Learn
View all
Membership not found