任何人都可以检查下面的代码,让我知道为什么我总是假的(User.Identity.IsAuthenticated)??我正确地在浏览器上获取cookie
能够从Claim获得价值,但“User.Identity.IsAuthenticated”总是错误的.
能够从Claim获得价值,但“User.Identity.IsAuthenticated”总是错误的.
public async Task<IActionResult> Login(string phoneNumber,int otp,string returnUrl) { if (this.accountService.ValidateOTP(phoneNumber,otp)) { var claims = new List<Claim> { new Claim(ClaimTypes.MobilePhone,phoneNumber),new Claim(ClaimTypes.Name,phoneNumber) }; var userIdentity = new ClaimsIdentity(); userIdentity.AddClaims(claim); ClaimsPrincipal userPrincipal = new ClaimsPrincipal(userIdentity); await HttpContext.Authentication.SignOutAsync("MyCookieMiddlewareInstance"); await HttpContext.Authentication.SignInAsync("MyCookieMiddlewareInstance",userPrincipal,new AuthenticationProperties { ExpiresUtc = DateTime.UtcNow.AddMinutes(20),IsPersistent = false,AllowRefresh = false }); if (string.IsNullOrWhiteSpace(returnUrl)) { return RedirectToAction("Create","Ad"); } else { return Redirect(returnUrl); } } return BadRequest(); }
解决方法
原文地址:https://www.jb51.cc/aspnet/245340.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。