描述一下BUG
A clear and concise description of what the bug is.
当我调用_signInManager.SignInAsync写入登录cookie时,cookie信息是写入成功的,但是请求时Profile中的User.Identity.IsAuthenticated 仍然是false,是我的调用姿势不对吗
重现步骤
Steps to reproduce the behavior:
Go to '...'
`[HttpPost]
[ModuleInfo]
[Description("用户登录")]
public async Task GoLogin(LoginDto dto)
{
IRecaptchaService _recaptcha = null;
Check.NotNull(dto, nameof(dto));
if (_recaptcha != null)
{
dto.IsCaptcha = true;
var recaptcha = await _recaptcha.Validate(Request);
if (!recaptcha.success)
{
ModelState.AddModelError("Recaptcha", "验证码错误,请确认重试");
return View(dto);
}
}
dto.Ip = HttpContext.GetClientIp();
dto.UserAgent = Request.Headers["User-Agent"].FirstOrDefault();
OperationResult result = await _identityContract.Login(dto);
IUnitOfWork unitOfWork = HttpContext.RequestServices.GetUnitOfWork<User, int>();
unitOfWork.Commit();
if (!result.Succeeded)
{
ModelState.AddModelError("Account", result.Message);
//return View(dto);
return RedirectToAction("Login", dto);
}
User user = result.Data;
` [HttpGet]
[ModuleInfo]
[Description("用户信息")]
public async Task Profile()
{
var data = HttpContext.User;
if (!User.Identity.IsAuthenticated)
{
return null;
}
描述一下BUG A clear and concise description of what the bug is. 当我调用_signInManager.SignInAsync写入登录cookie时,cookie信息是写入成功的,但是请求时Profile中的User.Identity.IsAuthenticated 仍然是false,是我的调用姿势不对吗 重现步骤 Steps to reproduce the behavior:
Go to '...' `[HttpPost] [ModuleInfo] [Description("用户登录")] public async Task GoLogin(LoginDto dto)
{
IRecaptchaService _recaptcha = null;
Check.NotNull(dto, nameof(dto));
if (_recaptcha != null)
{
dto.IsCaptcha = true;
var recaptcha = await _recaptcha.Validate(Request);
if (!recaptcha.success)
{
ModelState.AddModelError("Recaptcha", "验证码错误,请确认重试");
return View(dto);
}
}
dto.Ip = HttpContext.GetClientIp();
dto.UserAgent = Request.Headers["User-Agent"].FirstOrDefault();
OperationResult result = await _identityContract.Login(dto);
IUnitOfWork unitOfWork = HttpContext.RequestServices.GetUnitOfWork<User, int>();
unitOfWork.Commit();
if (!result.Succeeded)
{
ModelState.AddModelError("Account", result.Message);
//return View(dto);
return RedirectToAction("Login", dto);
}
User user = result.Data;
` [HttpGet] [ModuleInfo] [Description("用户信息")] public async Task Profile()
{
var data = HttpContext.User;
if (!User.Identity.IsAuthenticated)
{
return null;
}
期望行为 User.Identity.IsAuthenticated 应该为true
截图 If applicable, add screenshots to help explain your problem.
附加上下文,如截图 Add any other context about the problem here.
运行环境
Desktop (please complete the following information):