语言

StreamWebSocket.ServerCustomValidationRequested 活动

定义

在验证与安全服务器 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 要求

要求 说明
设备系列
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 。

适用于