SignalR Context.User is null

本文关键字:null is User Context SignalR | 更新日期: 2023-09-27 17:56:39

这是我的类MyHub

public class MyHub : Hub
{
    public bool AuthenRequest(string customerId, string sessionAccount, byte[] cusId)
    {
        bool Authen = ATDChatServer.Instance.OnAuthenRequest(customerId, sessionAccount, cusId);
        if (Authen)
        {
            var user = Context.User;
            return user.Identity.IsAuthenticated;
        }
        return false;
    }
}

它抛出异常用户为空。

我已经搜索了一些解决方案,其中之一是:这里

ConfigureAuth(app);
app.MapSignalR();

但是当我将此代码插入我的 StartUp 类时:

ConfigureAuth(app);

它显示错误:当前文本中不存在名称"配置身份验证(应用程序)"?

如何插入?

SignalR Context.User is null

ConfigureAuth 不是您需要包含的某个框架或库的一部分。它是一种实现。如果新增了具有身份验证的 MVC 项目,则会看到设置身份验证管道的"默认"实现。您也可以从这里了解更多信息,http://blogs.msdn.com/b/webdev/archive/2013/07/03/understanding-owin-forms-authentication-in-mvc-5.aspx