StreamWebSocket.ServerCustomValidationRequested 事件

定義

發生于已驗證安全伺服器 URI 的新 StreamWebSocket 連線 (wss: 通訊協定) 時。 如果您想要實作連線的自訂伺服器驗證,請處理此事件。

// Register
event_token ServerCustomValidationRequested(TypedEventHandler<StreamWebSocket, WebSocketServerCustomValidationRequestedEventArgs const&> const& handler) const;

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

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

事件類型

Windows 需求

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

備註

請注意,此事件會在成功執行預設 OS 驗證之後引發,而且預設 OS 驗證封裝含將 IgnorableServerCertificateErrors 控制選項納入考慮。

使用 WebSocketServerCustomValidationRequestedEventArgs 屬性來存取提供用於驗證的伺服器憑證和中繼憑證。

為了確保正確完成,如果您的自訂驗證程式牽涉到任何非同步作業,請務必使用 WebSocketServerCustomValidationRequestedEventArgs.GetDeferral 方法來取得事件處理常式在驗證作業期間保留的延遲物件。 驗證完成時,不論您接受或拒絕驗證,都必須呼叫 Deferral.Complete

作為您可以在此事件處理常式中執行的驗證類型範例:您可以將伺服器憑證與符合預期伺服器憑證的本機儲存信任憑證進行比較。 在事件處理常式中,您會比較本機憑證的 SHA-256 雜湊與伺服器憑證的雜湊。 如果雜湊值相符,則會假設憑證符合,而且伺服器驗證應該會成功。 如果雜湊值不相符,則憑證不符,驗證應該會失敗。

若要指出驗證失敗,請呼叫 WebSocketServerCustomValidationRequestedEventArgs.Reject 方法。 若要指出驗證成功,只要從事件處理常式傳回即可。

請注意,不論驗證成功或失敗,您都必須在開始驗證程式時取得的延遲物件上呼叫 Deferral.Complete

適用於