将SecWebSocketProtocol标头(SubProtocol)添加到ASP Web API 2中的WebSocketHandler

时间:2017-07-20 07:40:22

标签: asp.net iis asp.net-web-api websocket

ASP Web API中,升级到WebSocket需要初始化Microsoft.Web.WebSockets.WebSocketHandler。这种类型的WebSocket没有提供添加SecWebSocketProtocol标头的选项,这对我的情况很重要(MQTT超过WebSockets)。

public HttpResponseMessage Get()
{
    if (HttpContext.Current.IsWebSocketRequest || HttpContext.Current.IsWebSocketRequestUpgrading)
    {
       HttpContext.Current.AcceptWebSocketRequest(new WebSocketHandler());
       return Request.CreateResponse(HttpStatusCode.SwitchingProtocols);
    }

    else return new HttpResponseMessage(HttpStatusCode.BadRequest);
}

如何将此字段添加到WebSocketHandler?

0 个答案:

没有答案