简体   繁体   English

asp.net核心2身份“记住我”不起作用

[英]asp.net core 2 identity “Remember me” does not work

I have created a new asp.net core2 web application using Individual User Accounts - I'm new to asp.net core identity. 我已经使用个人用户帐户创建了一个新的asp.net core2 Web应用程序-我是asp.net核心身份的新手。 I'm using VS 2017. I've made no change to the code generated by VS. 我正在使用VS2017。我没有对VS生成的代码进行任何更改。 I ran the project and registered a new user successfully. 我运行了该项目并成功注册了一个新用户。 But when I login and check the "Remember me?" 但是,当我登录并选中“记住我吗?” checkbox, then after signing out and trying to sign in again, It forgoes me and I must type my username and password again! 复选框,然后退出并尝试再次登录后,它已被我放弃,我必须再次输入用户名和密码! So what is the problem? 那是什么问题呢?

You can use LoginInputModel model in [HttpBody] ==> it is contains Login data, so and make sure the value model.RememberMe is true Or not 您可以在[HttpBody] ==>中使用LoginInputModel modelLoginInputModel model包含Login数据,所以请确保值model.RememberMetrue或不是

[HttpPost]
[AllowAnonymous]
public async Task<IActionResult> doLogin(LoginInputModel model, string returnUrl = null)
{
  if (User.Identity.IsAuthenticated)
  {

    return RedirectToAction("Index", "Home");
  }

  ViewData["ReturnUrl"] = returnUrl;
  if (ModelState.IsValid)
  {


    try {

    var result = await _signManager.PasswordSignInAsync(MyUser, model.Password, model.RememberMe, lockoutOnFailure: false);// ==>> model.RememberMe = true

    .
    .
    .
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM