Esempio n. 1
0
        public async Task <IActionResult> Login(string _password)
        {
            var authprop = new Microsoft.AspNet.Http.Authentication.AuthenticationProperties();

            if (_password == _appsetting.Password)
            {
                authprop.ExpiresUtc = DateTime.UtcNow.AddMinutes(_appsetting.CookieTime);
                List <Claim> claims = new List <Claim>();
                claims.Add(new Claim("Name", _appsetting.UserName, ClaimValueTypes.String));
                claims.Add(new Claim(ClaimTypes.Name, _appsetting.UserName, ClaimValueTypes.String));
                ClaimsIdentity  identity  = new ClaimsIdentity(claims, "AuthenticationType", "Name", ClaimTypes.Role);
                ClaimsPrincipal principal = new ClaimsPrincipal(identity);
                await HttpContext.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, authprop);

                return(RedirectToAction("Index", "Admin"));
            }
            return(View("CalmDown"));
        }
Esempio n. 2
0
 public async Task<IActionResult> Login(string _password)
 {
     var authprop = new Microsoft.AspNet.Http.Authentication.AuthenticationProperties();
     if (_password == _appsetting.Password)
     {
         authprop.ExpiresUtc = DateTime.UtcNow.AddMinutes(_appsetting.CookieTime);
         List<Claim> claims = new List<Claim>();
         claims.Add(new Claim("Name", _appsetting.UserName, ClaimValueTypes.String));
         claims.Add(new Claim(ClaimTypes.Name, _appsetting.UserName, ClaimValueTypes.String));
         ClaimsIdentity identity = new ClaimsIdentity(claims, "AuthenticationType", "Name", ClaimTypes.Role);
         ClaimsPrincipal principal = new ClaimsPrincipal(identity);
         await HttpContext.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, authprop);
         return RedirectToAction("Index", "Admin");
     }
     return View("CalmDown");
 }