从另一个应用程序使用SignalR hub

时间:2016-10-15 08:05:18

标签: c# asp.net signalr.client

我有两个带有Windows身份验证的asp.net应用程序 应用A:有SignalR中心

[HubName("docHub")]
public class DocumentHub : Hub
{
    private static IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext<DocumentHub>();

    public void ReloadMenu()
    {
        Clients.All.ReloadMenu();
    }

    public void Reload()
    {
        Clients.All.Reload();
    }
}

应用B:使用App A调用SignalR client的中心方法

public void CallHub()
{
    var url = string.Format("http://{0}/signalr/", HttpContext.Current.IsDebuggingEnabled ? "localhost:2051" : "kms.local");
    var hubConn = new HubConnection(url, false);
    hubConn.Credentials = System.Net.CredentialCache.DefaultCredentials;
    var hubProxy = hubConn.CreateHubProxy("docHub");
    hubConn.Start().Wait();
    hubProxy.Invoke("Reload");
    hubProxy.Invoke("ReloadMenu");
}

我的问题是hubConn.Start().Wait();行问题,我得到Unauthorized例外。堆栈跟踪:

Exception information: 
    Exception type: HttpClientException 
    Exception message: StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Cache-Control: private
  WWW-Authenticate: Negotiate
  WWW-Authenticate: NTLM
  X-UA-Compatible: IE=Edge
  Date: Sat, 15 Oct 2016 07:16:27 GMT
  Content-Length: 6286
  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)



Request information: 
    Request URL: http://kms.local/WebDav/filename.xlsx 
    Request path: /WebDav/filename.xlsx 
    User host address: 172.00.00.00 
    User: DOMAIN\username 
    Is authenticated: True 
    Authentication Type: Negotiate 
    Thread account name: NT AUTHORITY\NETWORK SERVICE 

Thread information: 
    Thread ID: 61 
    Thread account name: NT AUTHORITY\NETWORK SERVICE 
    Is impersonating: False 
    Stack trace:    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)

由于这两个应用都有Windows身份验证方法,我不知道如何授权应用b的请求。

0 个答案:

没有答案