ServicePointManager.CertificatePolicy 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注意
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 将使用在该实例中定义的证书策略,而不是默认证书策略。
默认证书策略允许有效的证书和已过期的有效证书。