Guest User

Guest User

  • Tech Writer
  • 611
  • 126.2k

Remember me in .net core.

Nov 1 2020 11:14 PM
Hello Everyone
 
i have used this code for remember me in asp.net core. Remember me is not working. What's the issue with this code.
  1. if (ModelState.IsValid)  
  2. {  
  3. var userdetails = await _context.UserMaster  
  4. .SingleOrDefaultAsync(m => m.Email == model.Email && m.Password == model.Password);  
  5. if (userdetails == null)  
  6. {  
  7. ModelState.AddModelError("""The user name or password is incorrect.");  
  8. return View("Login");  
  9. }  
  10. if (userdetails != null)  
  11. {  
  12. if (userdetails.UserRoleId == 1)  
  13. {  
  14. var claims = new List<Claim>();  
  15. claims.Add(new Claim(ClaimTypes.Name, userdetails.Email));  
  16. var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);  
  17. var principal = new ClaimsPrincipal(identity);  
  18. var props = new AuthenticationProperties();  
  19. props.IsPersistent = model.RememberMe;  
  20. HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, props).Wait();  
  21. HttpContext.Session.SetString("Name", userdetails.FullName);  
  22. HttpContext.Session.SetString("Image", userdetails.Image);  
  23. HttpContext.Session.SetString("Id", Convert.ToString(userdetails.UserId));  
  24. string a = HttpContext.Session.GetString("Name");  
  25. string b = HttpContext.Session.GetString("Image");  
  26. string c = HttpContext.Session.GetString("Id");  
please let me solution what's issue

Answers (2)