쿠키에 액세스하여 사용자 및 암호를 가져온 다음 해당보기에서 "내 정보 저장"확인란을 선택 했으므로 로그인보기의 텍스트 상자에 설정해야합니다 ".C# MVC 5 양식 인증이 해제되면 티켓 쿠키가 지워집니다
로그 오프 방법에 성공적으로 로그인 한 후 세션과 쿠키의
public ActionResult LogOff()
{
//Session.Abandon();
// sign out.
FormsAuthentication.SignOut();
return RedirectToAction("Index", "Login");
}
초기화. 로그인보기 내가 먼저 로그 아웃하고 쿠키를 액세스하려고 문제가 있지만 실행하기 때문에 null을 반환의
private void InitializeSessionVariables(AgentDTO user)
{
// SessionModel.AgentId = user.ID;
Response.Cookies.Clear();
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,user.MobilePhone,DateTime.Now,DateTime.Now.AddDays(30),true,"",FormsAuthentication.FormsCookiePath);
// Encrypt the ticket.
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
// Create the cookie.
HttpCookie authenticationCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); // Name of auth cookie (it's the name specified in web.config) // Hashed ticket
authenticationCookie.Expires = DateTime.Now.AddDays(365);
// Add the cookie to the list for outbound response
Response.Cookies.Add(authenticationCookie);
}
액션 결과 "FormsAuthentication.SignOut();"
public ActionResult Index(LogonDTO model, string message = null, string reason = null)
{
if (SessionModel.AgentMobilePhone != null) return RedirectToAction("Index", "Home");
if (reason != null) message = "Su sessión ha expirado. Vuelva a loguearse.";
ViewBag.Message = message;
if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
{
HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
model.Username = authTicket.Name;
//model.Password = "in progress..."
}
return View(model);
}
https://support.microsoft.com/en-us/help/910443/understanding-the-forms-authentication-ticket-and-cookie에서 'FormsAuthentication.SignOut();'을 누르면 제거됩니다. 어쨌든 쿠키. 영구 쿠키의 경우 FormsAuthentication.SignOut();을 호출하지 않는다고 가정합니다. – Patrick
그래서, 제 경우에는 쿠키를 결코 지워야합니까? – Necroimix
사용자가 여전히 티켓/쿠키를 가지고 있지만 서버에 열린 세션이없는 경우에만 FormsAuthentication.SignOut();을 사용해야한다고 생각합니다. 이렇게하면 사용자의 브라우저에서 티켓이 제거되고 다시 "로그인"됩니다. – Patrick