共用方式為


ServicePointManager.CertificatePolicy 屬性

定義

警告

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

取得或設定伺服器憑證原則。

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

屬性值

實作 ICertificatePolicy 介面的物件。

屬性

範例

下列程式代碼範例示範如何攔截自定義憑證原則的憑證原則例外狀況。 它假設已定義憑證原則物件、Web 資源的統一資源標識碼 (URI) 包含在 變數 myUri中,而且有一個名為 ProcessResponse 的方法可執行應用程式的工作。

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

備註

CertificatePolicy當 屬性設定為ICertificatePolicy介面物件時,ServicePointManager物件會使用該實例中定義的憑證原則,而不是預設憑證原則。

默認憑證原則允許有效憑證和已過期的有效憑證。

適用於

另請參閱