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.

Атрибуты

Примеры

В следующем примере кода показано, как перехватывать исключение политики сертификатов для настраиваемой политики сертификатов. Предполагается, что объект политики сертификата определен, что универсальный код ресурса (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 определенную в этом экземпляре, вместо политики сертификатов по умолчанию.

Политика сертификатов по умолчанию разрешает допустимые сертификаты и действительные сертификаты, срок действия которых истек.

Применяется к

См. также раздел