【问题标题】:WebSockets in ASP.NET 5 (DNX) hosted on IIS not workingIIS 上托管的 ASP.NET 5 (DNX) 中的 WebSocket 无法正常工作
【发布时间】:2016-01-04 07:58:23
【问题描述】:

我的网站使用带有 RC1-Update1 的 ASP.NET 5,并且与客户端的一些通信通过 Web 套接字(使用 SignalR)。

在测试过程中,我发现在 IIS(或 IIS Express)上运行时,无法通过套接字进行通信。 SignalR 回退到长轮询。

SignalR 日志:

SignalR: Client subscribed to hub 'chathub'.
SignalR: Negotiating with '/signalr/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D'.
SignalR: serverSentEvents transport starting.
SignalR: Attempting to connect to SSE endpoint 'http://localhost:31650/signalr/signalr/connect?transport=serverSentEvents&c…wVlnXCY8bI7R8E&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&tid=2'.
SignalR: serverSentEvents transport timed out when trying to connect.
SignalR: EventSource calling close().
SignalR: serverSentEvents transport failed to connect. Attempting to fall back.
SignalR: foreverFrame transport starting.
SignalR: Forever Frame is not supported by SignalR on browsers with SSE support.
SignalR: foreverFrame transport failed to connect. Attempting to fall back.
SignalR: longPolling transport starting.
SignalR: Opening long polling request to 'http://localhost:31650/signalr/signalr/connect?transport=longPolling&client…8WRrhWwVlnXCY8bI7R8E&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D'.
SignalR: Long poll complete

经过长时间的调试,我通过命令行直接通过 dnx(没有 IIS 或其他任何东西)启动了我的网站:

dnx web

并且网络套接字工作开箱即用,没有任何问题。

在我对解决方案的研究过程中,我发现在带有 socket.io Web 应用程序的 nodejs 中,必须禁用 IIS 中的 Web 套接字,以便它们正确转发到 nodejs(链接到资源 here on iis.net),所以我尝试了同样的事情并得到了错误(webSocket 元素出现在 web.config 中时立即发生):

尝试确定托管您的应用程序的 DNX 进程的进程 ID 时发生错误。

我的 web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
        </handlers>
        <httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" forwardWindowsAuthToken="false" stdoutLogEnabled="true" startupTimeLimit="3600" />
        <staticContent>
            <!-- A bunch of mime types (no difference if removed) -->
        </staticContent>
        <webSocket enabled="false" />
    </system.webServer>
</configuration>

在这一点上,我已经没有想法了。我确保我在 Windows 功能中安装了 WebSockets,并尝试在 Azure 上部署我的网站(打开 Web 套接字),完成后将在其中托管它。

我会说问题是网络套接字没有被转发到 DNX,但找不到解决方案。任何帮助将不胜感激。

更新

Solution where the problem is recreated.

【问题讨论】:

    标签: iis websocket signalr asp.net-core dnx


    【解决方案1】:

    问题在于缺少包Microsoft.AspNet.WebSockets.Server 并调用startup.cs app.UseWebSockets()

    问题已在 GitHub 解决,非常感谢 @davidfowl。

    【讨论】:

    • 效果很好!缺少这个包我也有同样的问题。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-30
    • 1970-01-01
    • 2016-01-21
    相关资源
    最近更新 更多