語言

MessageWebSocket.ServerCustomValidationRequested 活動

定義

當一個新的 MessageWebSocket 連線到安全伺服器 URI(wss: 協定)正在驗證時發生。 如果你想為連線實作自訂伺服器驗證,就處理這個事件。

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

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

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

適用於