HttpBaseProtocolFilter.ServerCustomValidationRequested 事件

定義

當 SSL/TLS 連線與伺服器建立時,就會引發此事件。 如果您需要執行額外的驗證 (,以及伺服器 SSL 憑證的 OS 預設) ,您應該實作此事件的事件處理常式。

// Register
event_token ServerCustomValidationRequested(TypedEventHandler<HttpBaseProtocolFilter, HttpServerCustomValidationRequestedEventArgs const&> const& handler) const;

// Revoke with event_token
void ServerCustomValidationRequested(event_token const* cookie) const;

// Revoke with event_revoker
HttpBaseProtocolFilter::ServerCustomValidationRequested_revoker ServerCustomValidationRequested(auto_revoke_t, TypedEventHandler<HttpBaseProtocolFilter, HttpServerCustomValidationRequestedEventArgs const&> const& handler) const;
public event TypedEventHandler<HttpBaseProtocolFilter,HttpServerCustomValidationRequestedEventArgs> ServerCustomValidationRequested;
function onServerCustomValidationRequested(eventArgs) { /* Your code */ }
httpBaseProtocolFilter.addEventListener("servercustomvalidationrequested", onServerCustomValidationRequested);
httpBaseProtocolFilter.removeEventListener("servercustomvalidationrequested", onServerCustomValidationRequested);
- or -
httpBaseProtocolFilter.onservercustomvalidationrequested = onServerCustomValidationRequested;
Public Custom Event ServerCustomValidationRequested As TypedEventHandler(Of HttpBaseProtocolFilter, HttpServerCustomValidationRequestedEventArgs) 

事件類型

Windows 需求

裝置系列
Windows 10 Anniversary Edition (已於 10.0.14393.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v3.0 引進)

備註

在引發此事件之前,會先執行伺服器憑證的預設 OS 驗證。 如果憑證失敗此驗證,則連線會終止,而且未呼叫您的事件處理常式。

若要略過作業系統驗證的部分 (不建議用於生產案例) ,請使用 IgnoreableServerCertificateErrors 屬性來指定您想要忽略的錯誤。 然後,只要憑證沒有任何其他錯誤,OS 驗證就會被視為成功,而且系統會呼叫您的事件處理常式。

在 SSL/TLS 連線建立期間,事件處理常式程式碼會在 OS 中作為同步回呼的一部分執行。 避免在事件處理常式程式碼中執行長時間執行的工作,以防止伺服器在連線期間逾時。

如果您需要在事件處理常式程式碼內呼叫非同步 API,您必須先接受延遲 (請參閱 HttpServerCustomValidationArgs.GetDeferral) ,再呼叫非同步 API。 完成之後,請呼叫 延遲。從 處理常式程式碼傳回控制項的完整方法。

下列程式碼片段示範如何訂閱此事件。

HttpBaseProtocolFilter.ServerCustomValidationRequest += (sender, args) =>
{
	var cert = args.ServerCertificate
	// Your custom cert validation code here.
}

適用於