HTTPS And VB.Net Apps

  • Thread starter Thread starter tomb
  • Start date Start date
T

tomb

Saeid Bagheri asked a very good question, and I've seen this question
here before but I have never seen it answered. Can VB.Net desktop apps
utilize https? If so, how?

Tom
 
Saeid Bagheri asked a very good question, and I've seen this question
here before but I have never seen it answered. Can VB.Net desktop apps
utilize https? If so, how?

Tom

I asked about this myself some weeks ago in the context of simply wanting to download selected files
with HTTPS urls using WebClient. The current Help file talks about how to do this, but leads to an
example that returns a warning/error that the method is obsolete. The current Help file (nor MSDN)
had any example on how to use the suggested replacement method.

For my particular needs, I eventually wound up with this relatively simple method:

Imports System.Net.Security
Imports System.Security.Crytopgaphy.X509Certificates

Try
ServicePointManager.ServerCertificateValidationCallback = New _
RemoteCertificateValidationCallback(AddressOf ValidateCertificate)

WebClient1.DownloadDataAsync(uri)

Catch


End Try

Private Function ValidateCertificate(ByVal sender As Object, _
ByVal certificate As X509Certificate, ByVal chain As X509Chain, _
ByVal sslPolicyErrors As SslPolicyErrors) As Boolean

'Return True to force the certificate to be accepted.
Return True
End Function

In the above snippet, when the URI contains HTTPS, the certificate is accepted (the user ceritficate
dialog is not displayed) and the download preceeds. This works for my specific need in this case,
but others may want user intereaction with the certificate dialog.

Gene
 
EXCELLENT!!!

T

gene said:
I asked about this myself some weeks ago in the context of simply wanting to download selected files
with HTTPS urls using WebClient. The current Help file talks about how to do this, but leads to an
example that returns a warning/error that the method is obsolete. The current Help file (nor MSDN)
had any example on how to use the suggested replacement method.

For my particular needs, I eventually wound up with this relatively simple method:

Imports System.Net.Security
Imports System.Security.Crytopgaphy.X509Certificates

Try
ServicePointManager.ServerCertificateValidationCallback = New _
RemoteCertificateValidationCallback(AddressOf ValidateCertificate)

WebClient1.DownloadDataAsync(uri)

Catch


End Try

Private Function ValidateCertificate(ByVal sender As Object, _
ByVal certificate As X509Certificate, ByVal chain As X509Chain, _
ByVal sslPolicyErrors As SslPolicyErrors) As Boolean

'Return True to force the certificate to be accepted.
Return True
End Function

In the above snippet, when the URI contains HTTPS, the certificate is accepted (the user ceritficate
dialog is not displayed) and the download preceeds. This works for my specific need in this case,
but others may want user intereaction with the certificate dialog.

Gene
 
Back
Top