Click here to Skip to main content
15,881,248 members
Articles / Web Development / IIS
Tip/Trick

Bypass and Restore SSL Certificate Validation in VB.NET

Rate me:
Please Sign up or sign in to vote.
4.75/5 (4 votes)
30 Jan 2012CPOL 86.8K   7   4
How to bypass SSL certificate validation checking and restore it

Introduction


Sometimes when developing web applications, we get an exception when calling web service/another web application with HTTPS on the URL:


The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.


The best solution is by installing the SSL certificate on the web server, where you can find here. However sometimes your network engineers told you that they have installed it, but it is still throwing an exception.


A workaround to this issue is to bypass the SSL certificate validation. It is not the best solution, but it works, especially when your network people cannot resolve this issue and you have no authority to touch the production server.


Bypass SSL Certificate Validation


To bypass the SSL certificate validation, we will need to add some code like below:


VB.NET
'ByPass SSL Certificate Validation Checking
System.Net.ServicePointManager.ServerCertificateValidationCallback = _
  Function(se As Object, _
  cert As System.Security.Cryptography.X509Certificates.X509Certificate, _
  chain As System.Security.Cryptography.X509Certificates.X509Chain, _
  sslerror As System.Net.Security.SslPolicyErrors) True

'Call web application/web service with HTTPS URL

'Restore SSL Certificate Validation Checking
System.Net.ServicePointManager.ServerCertificateValidationCallback = Nothing

The first block will bypass any SSL certificate validation checking, while the last block is to restore the SSL certificate validation checking.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Singapore Singapore
Robby Tendean had his Master Degree in Computer Science from National Taiwan University of Science and Technology. His master degree thesis, Energy-Efficient Routing Protocol for Wireless Sensor Networks with Static Clustering and Dynamic Structure, has been published in Springerlink International Journal.

Currently he is working as Software Engineer based in Singapore with several years experience in HTML, Javascript, JQuery, C#.NET, VB.NET, Microsoft SQL Server for web development.

Comments and Discussions

 
QuestionBypass and Restore SSL Certificate Validation in VB.NET - Works for me Pin
Member 1442620616-Jun-20 10:46
Member 1442620616-Jun-20 10:46 
QuestionBypassing SSL Certificidate validation Pin
Member 148041587-May-20 3:05
Member 148041587-May-20 3:05 
QuestionWorks perfect but.. Pin
Member 1023637227-Aug-13 15:03
Member 1023637227-Aug-13 15:03 
AnswerPlain and simple Pin
miguelss17-Dec-12 9:08
professionalmiguelss17-Dec-12 9:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.