C# 使用SignalR客户端从控制台应用程序通过身份验证连接MVC项目中的SignalR hub

C# 使用SignalR客户端从控制台应用程序通过身份验证连接MVC项目中的SignalR hub,c#,model-view-controller,signalr,C#,Model View Controller,Signalr,我有一个MVC项目,其中包含一个信号集线器,只有经过身份验证的用户才能连接到该集线器。我的MVC项目中的Hub类如下所示: [Authorize] public class DataHub : Hub { public void Send(string message) { ... } } 我需要在本地控制台应用程序项目中连接到此中心。我已成功使用以下代码登录到MVC: CookieContainer cookies = new CookieContai

我有一个MVC项目,其中包含一个信号集线器,只有经过身份验证的用户才能连接到该集线器。我的MVC项目中的Hub类如下所示:

[Authorize]
public class DataHub : Hub
{
    public void Send(string message)
    {
        ...
    }
}
我需要在本地控制台应用程序项目中连接到此中心。我已成功使用以下代码登录到MVC:

CookieContainer cookies = new CookieContainer();
HttpClientHandler handler = new HttpClientHandler();
handler.CookieContainer = cookies;

HttpClient client = new HttpClient(handler);
var respTxt1 = client.GetStringAsync("https://localhost:44372/").Result;
// Finding __RequestVerificationToken in login view page.
respTxt1 = respTxt1.Substring(respTxt1.IndexOf("\"__RequestVerificationToken\""));
respTxt1 = respTxt1.Substring(respTxt1.IndexOf("value=\""));
respTxt1 = respTxt1.Substring(respTxt1.IndexOf("\"") + 1);
var __RequestVerificationToken = respTxt1.Substring(0, respTxt1.IndexOf("\""));

var values = new Dictionary<string, string>{
            { "Username", "*My Registered Username*" },
            { "Password", "*Password*" },
            { "__RequestVerificationToken", __RequestVerificationToken }
};
var content = new FormUrlEncodedContent(values);
var resp2 = client.PostAsync("https://localhost:44372/Account/Login?", content).Result;
提出的例外是
SocketException:无法建立连接,因为目标计算机主动拒绝了它127.0.0.1:44339

您是否配置了CORS?我认为这与CORS无关。MVC应用程序中的一些数据需要不断更新,我想使用通过signalr连接到MVC应用程序的控制台应用程序来更新它们。
var signalrConnection = new HubConnection("https://localhost:44339/");
signalrConnection.CookieContainer = cookies; // cookies is initiated in the previous codeblock
IHubProxy myHub = signalrConnection.CreateHubProxy("DataHub");
signalrConnection.Start().Wait();