Microsoft.ASPNET.SignalR.HttpClientException:内部服务器错误(500) - 如何调试它?

时间:2017-09-09 19:08:08

标签: c# asp.net .net signalr iis-8.5

当我尝试使用带有UWP的Microsoft.ASPNET.SignalR.Client库和下面的代码连接我的ASP.NET网站(在IIS 8.5上托管)时,我在标题中获得了异常。

var username = InitializeNickname();
Messages = new ObservableCollection<ChatMessage>();
Users = new ObservableCollection<ChatUser>();

ChatConnection = new HubConnection("http://9...0:8004/", new Dictionary<string, string>()
{
    {"user", username },
    {"avatar", Avatar.ToString() }
});
ChatProxy = ChatConnection.CreateHubProxy("ChatHub");

// Event Handler Declarations
ChatProxy.On<string>("SendMessages", ReceiveMessages);
ChatProxy.On<string>("SyncUsers", SyncUsers);

// Open Connection
ChatConnection.Error += ChatConnection_Error;
try
{
    await ChatConnection.Start();
} catch (Exception ex)
{

}

异常详情:

{Microsoft.AspNet.SignalR.Client.Infrastructure.StartException: Error during start request. Stopping the connection.
---> System.AggregateException: One or more errors occurred. 
---> Microsoft.AspNet.SignalR.Client.HttpClientException: StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:{  Transfer-Encoding: chunked  Cache-Control: private  Date: Sat, 09 Sep 2017 20:53:33 GMT  Server: Microsoft-IIS/8.5  X-AspNet-Version: 4.0.30319  X-Powered-By: ASP.NET  Content-Type: text/html; charset=utf-8}   at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpClient.<>c__DisplayClass5_0.<Get>b__1(HttpResponseMessage responseMessage)
   at Microsoft.AspNet.SignalR.TaskAsyncHelper.TaskRunners`2.<>c__DisplayClass3_0.<RunTask>b__0(Task`1 t)   --- End of inner exception stack trace ---   --- End of inner exception stack trace ---   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()   at ChatAPI.Chat.<OpenConnection>d__26.MoveNext()}

这就是我的集线器的OnConnected方法。

public override async Task OnConnected()
{
    var username = Context.QueryString.Get("user");
    using (var xyz = new XYZ())
    {
        var recentMessages = xyz.xyzapchats.OrderByDescending(o => o.id).Take(50).OrderBy(o => o.id);
        var json = JsonConvert.SerializeObject(recentMessages);
        await Clients.Caller.SendMessages(json);
        var u = xyz.xyzapusers.FirstOrDefault(o => o.username == username);
        if (u == null)
        {
            u = new xyzapuser() { username = username };
            xyz.xyzapusers.Add(u);
        }
        u.online = 1;
        xyz.SaveChanges();
        var online = JsonConvert.SerializeObject(xyz.xyzapusers.Where(o => o.online > 0).OrderByDescending(o => o.online).ThenBy(o => o.username).ToList());
        await Clients.All.SyncUsers(online);
    }
}

这种行为的原因是什么?我在同一台服务器上托管另一个ASP.NET站点,还有SignalR&amp; Owin,它的工作正常。我这次可以做错什么?

有没有办法调试这种东西? logs文件夹中的IIS日志仅显示对服务器的请求。

编辑: 此外,这是我的配置文件:

<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="owin:AppStartup" value="XYZAPEX_Chat.Startup" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
    </httpModules>
  </system.web>
  <system.webServer>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <validation validateIntegratedModeConfiguration="false" />
    <modules>
      <remove name="ApplicationInsightsWebTracking" />
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
    </modules>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="XYZ" connectionString="server=localhost;user id=root;password=gn gdngfiorjt5io6j 5y54i;persistsecurityinfo=True;database=xyz" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
</configuration>

0 个答案:

没有答案