// This event handler for server certificate validation executes synchronously as part of the SSL/TLS handshake. // An app should not perform lengthy operations inside this handler. Otherwise, the remote server may terminate the connection abruptly. private async void MyCustomServerCertificateValidator(HttpBaseProtocolFilter sender, HttpServerCustomValidationRequestedEventArgs args) { // Get the server certificate and certificate chain from the args parameter. Certificate serverCert = args.ServerCertificate; IReadOnlyList <Certificate> serverCertChain = args.ServerIntermediateCertificates; // To illustrate the use of async APIs, we use the IsCertificateValidAsync method. // In order to call async APIs in this handler, you must first take a deferral and then // release it once you are done with the operation. The "using" statement // ensures that the deferral completes when control leaves the method. using (Deferral deferral = args.GetDeferral()) { try { bool isCertificateValid = await IsCertificateValidAsync(serverCert); if (!isCertificateValid) { args.Reject(); } } catch { // If we get an exception from IsCertificateValidAsync, we reject the certificate // (secure by default). args.Reject(); } } }
// This event handler for server certificate validation executes synchronously as part of the SSL/TLS handshake. // An app should not perform lengthy operations inside this handler. Otherwise, the remote server may terminate the connection abruptly. private async void MyCustomServerCertificateValidator(HttpBaseProtocolFilter sender, HttpServerCustomValidationRequestedEventArgs args) { // Get the server certificate and certificate chain from the args parameter. Certificate serverCert = args.ServerCertificate; IReadOnlyList<Certificate> serverCertChain = args.ServerIntermediateCertificates; // To illustrate the use of async APIs, we use the IsCertificateValidAsync method. // In order to call async APIs in this handler, you must first take a deferral and then // release it once you are done with the operation. The "using" statement // ensures that the deferral completes when control leaves the method. using (Deferral deferral = args.GetDeferral()) { try { bool isCertificateValid = await IsCertificateValidAsync(serverCert); if (!isCertificateValid) { args.Reject(); } } catch { // If we get an exception from IsCertificateValidAsync, we reject the certificate // (secure by default). args.Reject(); } } }