public void LogIn(Account account) { var accountEntry = new AccountEntry(account); var authTicket = new FormsAuthenticationTicket(1, account.Name, DateTime.Now, DateTime.Now.Add(FormsAuthentication.Timeout), true, accountEntry.Serialize()); var encryptedTicket = FormsAuthentication.Encrypt(authTicket); var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket) { Expires = DateTime.Now.Add(FormsAuthentication.Timeout), }; HttpContext.Current.Response.Cookies.Add(authCookie); var identity = new CustomIdentity(accountEntry, authTicket.Name); HttpContext.Current.User = new GenericPrincipal(identity, null); }
public CustomIdentity(AccountEntry accountEntry, string name) { Name = name; _accountEntry = accountEntry; }