コード例 #1
0
        public void IdentitySignin(UsuarioLogadoVM usuarioLogado, string providerKey = null, bool isPersistent = false)
        {
            var claims = new List<Claim>
            {
                new Claim(ClaimTypes.NameIdentifier, usuarioLogado.Email),
                new Claim(ClaimTypes.Name, usuarioLogado.Nome),
                new Claim(CustomClaimTypes.Setor, usuarioLogado.Setor)
            };

            if (usuarioLogado.Perfil != null)
            {
                claims.Add(new Claim(ClaimTypes.Role, usuarioLogado.Perfil.Nome));
                claims.Add(new Claim(CustomClaimTypes.Acoes, usuarioLogado.Perfil.Acessos));
            }

            var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

            AuthenticationManager.SignIn(new AuthenticationProperties()
            {
                AllowRefresh = true,
                IsPersistent = isPersistent,
                ExpiresUtc = DateTime.UtcNow.AddDays(7)
            }, identity);
        }
コード例 #2
0
 public static void RegistrarUsuarioLogadoEmSessao(UsuarioLogadoVM usuarioLogado)
 {
     HttpContext.Current.Session["UsuarioLogado"] = usuarioLogado;
 }