$.connection.hub.start().done() 上的错误 500

Error 500 on $.connection.hub.start().done()

在我现有的应用程序中,对 http://localhost:xxx/signalr/negotiate returns 500 的 get 请求,我无法获得有关找到实际原因的更多信息

我已经尝试创建一个全新的 MVC 项目并设置 SignalR - 这有效。

我已经尝试使用示例项目并配置为使用我的信号器服务,这些也有效。

在诊断工具和应用洞察门户中,我都看不到有关导致此错误 500 的原因的更多信息

chrome 中的开发工具也没有给我更多信息

它很长,但我能找到的最好的是来自 IISExpress 的日志,它有以下错误导致我认为它与我的应用程序强制执行的 permissions/access 有关,但我不知道从哪里开始寻找。

<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
 <System>
  <Provider Name="WWW Server" Guid="{3A2A4E84-4C21-4981-AE10-3FDA0D9B0F83}"/>
  <EventID>0</EventID>
  <Version>1</Version>
  <Level>3</Level>
  <Opcode>16</Opcode>
  <Keywords>0x100</Keywords>
  <TimeCreated SystemTime="2019-04-11T09:01:02.344Z"/>
  <Correlation ActivityID="{80000052-0004-FF00-B63F-84710C7967BB}"/>
  <Execution ProcessID="18156" ThreadID="13096"/>
  <Computer>DESKTOP-SQ9UCSB</Computer>
 </System>
 <EventData>
  <Data Name="ContextId">{80000052-0004-FF00-B63F-84710C7967BB}</Data>
  <Data Name="ModuleName">__DynamicModule_Microsoft.Owin.Host.SystemWeb.OwinHttpModule, Microsoft.Owin.Host.SystemWeb, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35_ed612830-d174-4c74-ba1f-93c69902f2c6</Data>
  <Data Name="Notification">4</Data>
  <Data Name="HttpStatus">500</Data>
  <Data Name="HttpReason">Internal Server Error</Data>
  <Data Name="HttpSubStatus">0</Data>
  <Data Name="ErrorCode">0</Data>
  <Data Name="ConfigExceptionInfo"></Data>
 </EventData>
 <RenderingInfo Culture="en-GB">
  <Opcode>MODULE_SET_RESPONSE_ERROR_STATUS</Opcode>
  <Keywords>
   <Keyword>RequestNotifications</Keyword>
  </Keywords>
  <freb:Description Data="Notification">AUTHORIZE_REQUEST</freb:Description>
  <freb:Description Data="ErrorCode">The operation completed successfully.
 (0x0)</freb:Description>
 </RenderingInfo>
 <ExtendedTracingInfo xmlns="http://schemas.microsoft.com/win/2004/08/events/trace">
  <EventGuid>{002E91E3-E7AE-44AB-8E07-99230FFA6ADE}</EventGuid>
 </ExtendedTracingInfo>
</Event>

如有任何帮助,我们将不胜感激!

谢谢, 汤姆


作为参考,这是我使用的代码

集线器是一个只有一个功能的基本设置

public void Send(string messageText)
{
    Clients.All.broadcastMessage(messageText);
}

在我的 setup.cs 中,我遵循了基本实现,但我添加了一些额外的调试(不是帮助!)

public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
            GlobalHost.HubPipeline.AddModule(new ErrorHandlingPipelineModule());
            app.MapAzureSignalR("/AzureSignalr", this.GetType().FullName, new HubConfiguration()
            {
                EnableDetailedErrors = true,
                EnableJSONP = true
            });
            GlobalHost.HubPipeline.RequireAuthentication();
        }

        private class ErrorHandlingPipelineModule : HubPipelineModule
        {
            protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
            {
                throw exceptionContext.Error;
            }
        }

最后,在我的 html 文件中,我再次遵循了基本实现,但我也尝试明确设置 url 并再次添加更多调试。

<script src="/Scripts/jquery-3.3.1.js"></script>
    <script src="/Scripts/jquery.signalR-2.4.0.js"></script>
    <script src="/AzureSignalr/hubs"></script>
    <script type="text/javascript">
        $(function () {
            var messages = $.connection.myHub;

            messages.client.broadcastMessage = function (message) {
                alert(message);
            };

            $.connection.hub.url = 'http://localhost:57690/AzureSignalr';
            $.connection.hub.connectionSlow(function () {
                console.log('We are currently experiencing difficulties with the connection.')
            });
            $.connection.hub.error(function (error) {
                console.log('SignalR error: ' + error)
            });
            $.connection.hub.start().done();
        });
    </script>

我现在已经设法找到了解决方案,感谢这里的另一个问题;

我将 startup.cs 更改为以下内容;

public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            app.MapAzureSignalR("/AzureSignalrPath", this.GetType().FullName, new HubConfiguration());
        }
    }

重要的因素是安全协议