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.
- if (ModelState.IsValid)
- {
- var userdetails = await _context.UserMaster
- .SingleOrDefaultAsync(m => m.Email == model.Email && m.Password == model.Password);
- if (userdetails == null)
- {
- ModelState.AddModelError("", "The user name or password is incorrect.");
- return View("Login");
- }
- if (userdetails != null)
- {
- if (userdetails.UserRoleId == 1)
- {
- var claims = new List<Claim>();
- claims.Add(new Claim(ClaimTypes.Name, userdetails.Email));
- var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
- var principal = new ClaimsPrincipal(identity);
- var props = new AuthenticationProperties();
- props.IsPersistent = model.RememberMe;
- HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, props).Wait();
- HttpContext.Session.SetString("Name", userdetails.FullName);
- HttpContext.Session.SetString("Image", userdetails.Image);
- HttpContext.Session.SetString("Id", Convert.ToString(userdetails.UserId));
- string a = HttpContext.Session.GetString("Name");
- string b = HttpContext.Session.GetString("Image");
- string c = HttpContext.Session.GetString("Id");
please let me solution what's issue