Bagikan melalui


ServicePointManager.CertificatePolicy Properti

Definisi

Perhatian

CertificatePolicy is obsoleted for this type, please use ServerCertificateValidationCallback instead. http://go.microsoft.com/fwlink/?linkid=14202

Mendapatkan atau menetapkan kebijakan untuk sertifikat server.

public:
 static property System::Net::ICertificatePolicy ^ CertificatePolicy { System::Net::ICertificatePolicy ^ get(); void set(System::Net::ICertificatePolicy ^ value); };
public static System.Net.ICertificatePolicy CertificatePolicy { get; set; }
[System.Obsolete("CertificatePolicy is obsoleted for this type, please use ServerCertificateValidationCallback instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Net.ICertificatePolicy CertificatePolicy { get; set; }
static member CertificatePolicy : System.Net.ICertificatePolicy with get, set
[<System.Obsolete("CertificatePolicy is obsoleted for this type, please use ServerCertificateValidationCallback instead. http://go.microsoft.com/fwlink/?linkid=14202")>]
static member CertificatePolicy : System.Net.ICertificatePolicy with get, set
Public Shared Property CertificatePolicy As ICertificatePolicy

Nilai Properti

Objek yang mengimplementasikan ICertificatePolicy antarmuka.

Atribut

Contoh

Contoh kode berikut menunjukkan cara menangkap pengecualian kebijakan sertifikat untuk kebijakan sertifikat kustom. Ini mengasumsikan bahwa objek kebijakan sertifikat telah ditentukan, bahwa Pengidentifikasi Sumber Daya Seragam (URI) untuk sumber daya Web terkandung dalam variabel myUri, dan bahwa ada metode bernama ProcessResponse yang melakukan pekerjaan aplikasi.

ServicePointManager::CertificatePolicy = gcnew MyCertificatePolicy;

// Create the request and receive the response
try
{
   WebRequest^ myRequest = WebRequest::Create( myUri );
   WebResponse^ myResponse = myRequest->GetResponse();
   ProcessResponse( myResponse );
   myResponse->Close();
}
// Catch any exceptions
catch ( WebException^ e ) 
{
   if ( e->Status == WebExceptionStatus::TrustFailure )
   {
      // Code for handling security certificate problems goes here.
   }
   // Other exception handling goes here
}
ServicePointManager.CertificatePolicy = new MyCertificatePolicy();

// Create the request and receive the response
try
{
    WebRequest myRequest = WebRequest.Create(myUri);
    WebResponse myResponse = myRequest.GetResponse();
    ProcessResponse(myResponse);
    myResponse.Close();
}
// Catch any exceptions
catch (WebException e)
{
    if (e.Status == WebExceptionStatus.TrustFailure)
    {
        // Code for handling security certificate problems goes here.
    }
    // Other exception handling goes here
}
ServicePointManager.CertificatePolicy = New MyCertificatePolicy()
       
' Create the request and receive the response
Try
    Dim myRequest As WebRequest = WebRequest.Create(myUri)
    Dim myResponse As WebResponse = myRequest.GetResponse()
    
    ProcessResponse(myResponse)

    myResponse.Close()
    
' Catch any exceptions
Catch e As WebException
    If e.Status = WebExceptionStatus.TrustFailure Then
        ' Code for handling security certificate problems goes here.
    End If
    ' Other exception handling goes here
 End Try

Keterangan

CertificatePolicy Ketika properti diatur ke ICertificatePolicy objek antarmuka, ServicePointManager objek menggunakan kebijakan sertifikat yang ditentukan dalam instans tersebut alih-alih kebijakan sertifikat default.

Kebijakan sertifikat default memungkinkan sertifikat yang valid dan sertifikat yang valid yang telah kedaluwarsa.

Berlaku untuk

Lihat juga