6
'da oturum açmıyor Geçerli kullanıcı veritabanından alabilir, ClaimsIdentity
'u oluşturabilir ve SignIn
yöntemi hatasız olarak çağrılabilir. AncakAuthenticationManager.SignIn(),
public ActionResult SignInConformation(SignInModel model)
{
if (ModelState.IsValid)
{
var user = _userManager.Find(model.Username, model.Password);
if (user == null)
{
ModelState.AddModelError("", "Invalid username and\\or password");
}
else
{
_authenticationManager.SignOut();
var claimsIdentity = _userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
_authenticationManager.SignIn(new AuthenticationProperties { IsPersistent = true }, claimsIdentity);
return RedirectToAction("Index", "Home");
}
}
return View();
}
, kullanıcı böyle görünüme oturum açmışsa ben kontrol edin:
<p>
Current User: @if (User.Identity.IsAuthenticated)
{
@User.Identity.Name
}
else
{
@:Unknown
}
</p>
IsAuthenticated
döner false
.