당신은이 작업을 수행 할 수 있습니다 -
FormsAuthenticationTicket _ticket = new FormsAuthenticationTicket(_version, _name, _issueDate, _expirationDate, _isPersistent, _userData, _cookiePath);
string _encryptedTicket = FormsAuthentication.Encrypt(_ticket);
HttpCookie _cookie = new HttpCookie("customticket", _encryptedTicket);
HttpContext.Current.Response.Cookies.Add(_cookie);
그런 다음 당신은 그들이이 쿠키가 있는지 확인하기 위해 들어오는 요청을 확인하는 코드를 작성할 수 있습니다 - 질문을 작성 후
HttpCookie _cookie = HttpContext.Current.Request.Cookies["customticket"];
if(_cookie){
_encryptedTicket = _cookie.Value;
FormsAuthenticationTicket _ticket = FormsAuthentication.Decrypt(_encryptedTicket);
if(!_ticket.Expired) {
IIdentity _identity = new FormsIdentity(_ticket);
IPrincipal _principal = new GenericPrincipal(_identity, new string[0]); //Identity plus string of roles.
}
}
else{
//dostuff
}
을, 이것은 내가 종료 된 접근 방식이다 올라가고있어. 감사! –
우수한 솔루션입니다. MVC 5 애플리케이션 중 하나에서 이것을 채택했습니다. – Tommassiov