asp.net-mvc – Context.User.Identity.Name为null与SignalR 2.X.X.
发布时间:2020-05-23 11:58:36 所属栏目:asp.Net 来源:互联网
导读:这让我疯狂。 我正在使用最新的signalR版本(2.0.2)。这是我的中心码(OnConnected) public override Task OnConnected() { //User is null then Identity and Name too. Connections.Add(Context.User.Identi
|
这让我疯狂。 我正在使用最新的signalR版本(2.0.2)。这是我的中心码(OnConnected) public override Task OnConnected()
{
//User is null then Identity and Name too.
Connections.Add(Context.User.Identity.Name,Context.ConnectionId);
return base.OnConnected();
}
这是我的Controller的登录方式: [HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model,string returnUrl)
{
if (ModelState.IsValid)
{
var user = await UnitOfWork.UserRepository.FindAsync(model.UserName,model.Password);
if (user != null)
{
await SignInAsync(user,model.RememberMe);
return RedirectToLocal(returnUrl);
}
}
TempData["ErrorMessage"] = Resources.InvalidUserNameOrPassword;
// If we got this far,something failed,redisplay form
return RedirectToAction("Index","Home");
}
我发现有些人在OnDisconnected上遇到这个问题,我甚至没有在那里。 我正在使用MCV5模板。 你有什么想法有什么问题吗? 解决方法我找到了最终的解决方案,这是我的OWIN启动类的代码:public void Configuration(IAppBuilder app)
{
app.MapSignalR();
// Enable the application to use a cookie to store information for the signed i user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,LoginPath = new PathString("/Home/Index")
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseMicrosoftAccountAuthentication(new MicrosoftProvider().GetAuthenticationOptions());
app.UseTwitterAuthentication(new TwitterProvider().GetAuthenticationOptions());
app.UseFacebookAuthentication(new FacebookProvider().GetAuthenticationOptions());
app.UseGoogleAuthentication(new GoogleProvider().GetAuthenticationOptions());
}
让我自己喝咖啡,我以为“在验证后映射SignalR如何,瞧!现在它按照预期工作。 public void Configuration(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed i user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,LoginPath = new PathString("/Home/Index")
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseMicrosoftAccountAuthentication(new MicrosoftProvider().GetAuthenticationOptions());
app.UseTwitterAuthentication(new TwitterProvider().GetAuthenticationOptions());
app.UseFacebookAuthentication(new FacebookProvider().GetAuthenticationOptions());
app.UseGoogleAuthentication(new GoogleProvider().GetAuthenticationOptions());
app.MapSignalR();
} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – HttpResponse.RemoveOutputCacheItem不工作
- asp.net – 如何崩溃App Pool?
- 当使用ASP.Net Membership和另外一个表来存储用户信息时,我
- asp.net – Page_Load中的Response.Redirect
- asp.net – 什么是crossdomain.xml文件?
- asp.net后台cs中的JSON格式变量在前台Js中调用方法(前后台示
- asp.net-mvc – 更改MVC4上的基本视图类型
- asp.net-mvc – 文件上传MVC
- 从ASP.NET应用程序使用Active Directory时,DirectoryServic
- asp.net下创建、查询、修改带名称空间的 XML 文件的例子
推荐文章
站长推荐
- asp.net-mvc – EF 4代码如何首先处理生产环境中
- asp.net – 更好的方式来获取页面名称
- asp.net-mvc – 可以浏览DataAnnotations的自定义
- asp.net-mvc – 从Action写入输出流
- asp.net – 如何在aspx文件中创建区域?
- asp.net – Microsoft MVC“echo / print / outp
- asp.net-core – 在ASP.NET Core MVC中,浏览器中
- SqlServer如何给表添加新的字段以及字段注释
- asp.net-mvc-3 – ASP.Net MVC3路由保留字?
- asp.net – 我可以动态更改嵌套母版页的主
热点阅读
