0

I have wrote a code like following:

   if (user.PasswordHash == Helpers.PasswordHelper.CreatePasswordHash(model.Password, user.PasswordSalt))
                        {

                            ClaimsIdentity identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie);
                            identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, model.Email));
                            List<Claim> claims = new List<Claim>();
                            var roles = user.UserRoles.Where(x => x.UserId == user.UserId).ToList();

                            foreach (var item in roles)
                            {
                                claims.Add(new Claim(ClaimTypes.Role, item.Roles.RoleName));
                            }
                            identity.AddClaims(claims);
                            identity.AddClaim(new Claim(ClaimTypes.Name, model.Email));

                            AuthenticationManager.SignIn(identity);

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

Inside my model I have the remember me property which I want to incorporate upon user login, how can I do that?

P.S. The value is bool and I just need to somehow now tell the browser what the user picked from the login menu...

User987
  • 3,663
  • 15
  • 54
  • 115
  • I think this answer might get you going in the right direction: http://stackoverflow.com/questions/19091157/how-do-you-login-authenticate-a-user-with-asp-net-mvc5-rtm-bits-using-aspnet-ide – R. Richards Jan 29 '17 at 14:35

1 Answers1

2

try this:

using Microsoft.Owin.Security;

...

AuthenticationManager.SignIn(new AuthenticationProperties(){IsPersistent = model.RememberMe}, identity);
antiduh
  • 11,853
  • 4
  • 43
  • 66