【发布时间】:2015-11-01 17:45:40
【问题描述】:
我正在学习 ASP.NET Identity 和 SignalR 等。我能够使用 Identity 的自定义实现创建自己的身份验证系统。我现在正在尝试在调用覆盖的 OnConnected 之前向 SignalR 验证用户的身份。
用户通过 Cookie Authentication 验证后,[System.Web.Mvc.Authorize] 属性成功通过,而[Microsoft.AspNet.SignalR] 属性告诉我用户尚未通过身份验证。
//This is my Authorize method:
[HttpGet]
public ActionResult Authorize()
{
AuthenticationManager.SignIn(new ClaimsIdentity(new ClaimsPrincipal(User).Claims.ToArray(), "Bearer"));
return new EmptyResult();
}
//This is my CookieAuthenticationOptions
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider()
});
//On the Hub
public override Task OnConnected()
{
string userName = Context.User.Identity.Name; //User is null?
}
我在这里缺少什么?我已经用谷歌搜索了一段时间,但我找不到任何东西,甚至不知道如何向 SignalR 进行身份验证。
【问题讨论】:
标签: c# asp.net asp.net-mvc authentication