我写了如下代码:
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");
}
在我的模型中,我有记住我的属性,我想在用户登录时合并它,我该怎么做?
附言值是布尔值,我现在只需要以某种方式告诉浏览器用户从登录菜单中选择了什么......
试试这个:
using Microsoft.Owin.Security;
...
AuthenticationManager.SignIn(new AuthenticationProperties(){IsPersistent = model.RememberMe}, identity);