TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
611
129.3k
Remember me in .net core.
Sep 3 2020 1:27 AM
I have code Login with remember me code.it's me code login is run but remember me not run .Please check this code.
[HttpPost]
[AllowAnonymous]
public
async Task<ActionResult> Login(UserLoginViewModel model)
{
try
{
if
(ModelState.IsValid)
{
var userdetails = await _context.UserMaster
.SingleOrDefaultAsync(m => m.Email == model.Email && m.Password == model.Password);
if
(userdetails ==
null
)
{
ModelState.AddModelError(
""
,
"Invalid login attempt."
);
return
View(
"Login"
);
}
if
(userdetails !=
null
)
{
if
(userdetails.UserRoleId == 1)
{
var userClaims =
new
List<Claim>()
{
new
Claim(ClaimTypes.Name,userdetails.Password),
new
Claim(ClaimTypes.Email, userdetails.Email),
};
var grandmaIdentity =
new
ClaimsIdentity(userClaims,
"UserIdentity"
);
var userPrincipal =
new
ClaimsPrincipal(
new
[] { grandmaIdentity });
await HttpContext.SignInAsync(userPrincipal,
new
AuthenticationProperties
{
IsPersistent = model.RememberMe,
ExpiresUtc = DateTime.Now.AddHours(1)
});
HttpContext.Session.SetString(
"AdminName"
, userdetails.FullName);
HttpContext.Session.SetString(
"AdminImage"
, userdetails.AdminImage);
string
a = HttpContext.Session.GetString(
"AdminName"
);
string
b = HttpContext.Session.GetString(
"AdminImage"
);
}
}
}
else
{
ModelState.AddModelError(
string
.Empty,
"The user name or password is incorrect"
);
return
View();
}
return
RedirectToAction(
"Dashboard"
,
"Dashboard"
);
}
catch
(Exception ex)
{
ViewBag.message =
"Internal Server Error"
;
var message = ex.InnerException.Message;
throw
;
}
}
[HttpPost]
public
IActionResult Logout()
{
HttpContext.SignOutAsync(
CookieAuthenticationDefaults.AuthenticationScheme);
return
RedirectToAction(
"Login"
,
"Login"
);
}
}
Reply
Answers (
2
)
How can I make watch app
Deserialize JSON with dynamic keys using C# Json.NET