| Visual Basic (Declaration) | |
|---|---|
Public Property Accept As Boolean | |
| Visual Basic (Usage) | Copy Code |
|---|---|
Dim instance As CertificateReceivedEventArgs Dim value As Boolean instance.Accept = value value = instance.Accept | |
| C# | |
|---|---|
public bool Accept {get; set;} | |
| Managed Extensions for C++ | |
|---|---|
public: __property bool get_Accept(); public: __property void set_Accept( bool value ); | |
Property Value
Boolean which determines whether or not a certificate is accepted.The following example demonstrates creating a simple secure client.
| Visual Basic | Copy Code |
|---|---|
Private Sub CertificateReceived(ByVal sender As Object, ByRef e As CertificateReceivedEventArgs) Handles Tcp1.CertificateReceived Dim msg As String = "The certificate was invalid for the following reason(s)" + vbCrLf ' Check to see if the certificate is from a trusted root. If Not e.TrustedRoot Then msg += "This certificate is not from a trusted root" + vbCrLf End If ' Check to see if the certificate has a valid date. If Not e.ValidDate Then msg += "This certificate does not have a valid date" + vbCrLf End If ' Check to see if the certificate has a valid name. If Not e.ValidName Then msg += "This certificate does not have a valid name" + vbCrLf End If If msg <> "" Then msg += "Would you like to accept this certificate anyway?" If MessageBox.Show(msg, "Invalid Cert Received", MessageBoxButtons.YesNo) = DialogResult.Yes Then e.Accept = True End If End If End Sub | |
| C# | Copy Code |
|---|---|
private void CertificateReceived(object sender, CertificateReceivedEventArgs e) { string msg = "The certificate was invalid for the following reason(s)\n"; // Check to see if the certificate is from a trusted root. if(!e.TrustedRoot) msg+= "This certificate is not from a trusted root\n"; // Check to see if the certificate has a valid date. if(!e.ValidDate) msg+= "This certificate does not have a valid date\n"; // Check to see if the certificate has a valid name. if(!e.ValidName) msg+= "This certificate does not have a valid name\n"; if(!e.Accept) { msg += "Would you like to accept this certificate anyway?"; if(MessageBox.Show(msg, "Invalid Cert Received", MessageBoxButtons.YesNo) == DialogResult.Yes) e.Accept = true; } } | |
If CertificateReceivedEventArgs.ValidDate, CertificateReceivedEventArgs.ValidName, and CertificateReceivedEventArgs.TrustedRoot are all true, this property will return true meaning the certificate was accepted. Set this property to false to override this and reject the certificate.
If any of the properties CertificateReceivedEventArgs.ValidDate, CertificateReceivedEventArgs.ValidName, and CertificateReceivedEventArgs.TrustedRoot are false, this property will return false meaning the certificate was not accepted. Set this property to true to override this and accept the certificate.
Target Platforms: Microsoft .NET Framework 2.0
Copy Code