StreamWebSocket.ServerCustomValidationRequested 活動
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當正在驗證與安全伺服器 URI(wss:協定)的新 StreamWebSocket 連線時,會發生這種情況。 如果你想為連線實作自訂伺服器驗證,就處理這個事件。
// 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 需求
| 規格需求 | Description |
|---|---|
| 裝置系列 |
Windows 10 Anniversary Edition (已於 10.0.14393.0 引進)
|
| API contract |
Windows.Foundation.UniversalApiContract (已於 v3.0 引進)
|
備註
請注意,此事件會在預設作業系統驗證成功執行後觸發,且預設作業系統驗證包含 IgnorableServerCertificateErrors 控制選項。
使用 WebSocketServerCustomValidationRequestedEventArgs 屬性來存取提供驗證的伺服器憑證及中間憑證。
為了確保正確完成,如果你的自訂驗證流程涉及任何非同步操作,請務必使用 WebSocketServerCustomValidationRequestedEventArgs.GetDeferral 方法,取得一個延遲物件,讓你的事件處理器在驗證操作期間保留該物件。 當你的驗證完成後,無論你接受或拒絕驗證,都必須致電 Deferral.Complete 。
舉例來說,你可以在這個事件處理程序中進行驗證:你可以將伺服器憑證與本地儲存的可信憑證比較,該憑證與預期的伺服器憑證相符。 在你的事件處理程序中,你會將本地憑證的 SHA-256 雜湊值與伺服器憑證的雜湊值做比較。 若雜湊值相符,則假定憑證相符,伺服器驗證應成功。 如果雜湊值不匹配,證書也不會匹配,驗證就會失敗。
若要指示驗證失敗,請呼叫 WebSocketServerCustomValidationRequestedEventArgs.Reject 方法。 要表示驗證成功,只需從事件處理程序返回即可。
請注意,無論驗證成功或失敗,你都必須對你在開始驗證過程時取得的延遲物件呼叫 Deferral.Complete 。