asp.net – 什么设置的User.Identity.Name和User.Identity.IsAut
发布时间:2020-12-16 06:39:14 所属栏目:asp.Net 来源:网络整理
导读:我想知道什么是用户身份名称,并且更改isAuthenticated为true. 为什么在SignInManager.PasswordSignInAsync返回Success后,User.Identity.Name为空字符串且User.Identity.IsAuthenticated为false. // POST: /Account/Login[HttpPost][AllowAnonymous][Validate
我想知道什么是用户身份名称,并且更改isAuthenticated为true.
为什么在SignInManager.PasswordSignInAsync返回Success后,User.Identity.Name为空字符串且User.Identity.IsAuthenticated为false. // POST: /Account/Login [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Login(LoginViewModel model,string returnUrl) { if (!ModelState.IsValid) { return View(model); } var userIdentityNameTest = User.Identity.Name; // Empty string var result = await SignInManager.PasswordSignInAsync( model.Email,model.Password,model.RememberMe,shouldLockout: false); // result is "Success" userIdentityNameTest = User.Identity.Name; // userIdentityNameTest is still an empty string? // User.Identity.IsAuthenticated is still false? switch (result) { case SignInStatus.Success: return RedirectToLocal(returnUrl); case SignInStatus.LockedOut: return View("Lockout"); case SignInStatus.RequiresVerification: return RedirectToAction("SendCode",new { ReturnUrl = returnUrl,RememberMe = model.RememberMe }); case SignInStatus.Failure: default: ModelState.AddModelError("","Invalid login attempt."); return View(model); } } 解决方法
似乎SignInManager.PasswordSignInAsync仅验证输入的数据,如果您没有使用TwoFactorAuthentication,则运行AuthenticationManager.SignIn.在这种情况下,AuthenticationManager.SignIn仅将身份验证cookie设置为响应.
因此,User.Identity可在随后的应用程序请求中使用.要按名称获取ApplicationUser,您可以使用ApplicationUserManager,如下所示: UserManager.FindByNameAsync(model.Name) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 从Web应用程序打印
- asp.net-mvc – MVC WebApi不使用AutofacWebApiDependencyR
- asp.net-mvc-5 – 使用ASP.NET MVC 5的Okta OWIN提供程序
- asp.net – 为什么我的主机(softsyshosting.com)不支持Begi
- asp.net-mvc – MVC中的模型含义
- asp.net-core – 在ASP.NET 5 MVC6中使用什么而不是WebView
- asp.net-mvc-3 – 向th添加一个类
- asp.net-mvc-4 – jQuery DatePicker MVC4 EditorFor
- asp.net – dropdownlist在页面重新加载时不会重置
- asp.net – 哪种模式最匹配场景详细,是不是很好的做法?
推荐文章
站长推荐
热点阅读