public static void SetAuthCookie(ILoginUser user) { Initialize(); if (!HttpContext.Current.Request.IsSecureConnection && RequireSSL) { throw new HttpException("Connection_not_secure_creating_secure_cookie"); } bool fromCookie = false; ILibAuthenticationTicket ticket = LibAuthentication.ExtractTicketFromCookie(ref fromCookie); if (ticket == null) { ticket = LibAuthentication.CreateTicket(user); } HttpCookie cookie = LibAuthentication.PrepareCookie(ticket, false); if (fromCookie) { HttpContext.Current.Response.Cookies.Remove(cookie.Name); HttpContext.Current.Response.Cookies.Add(cookie); } else { HttpContext.Current.Response.Cookies.Add(cookie); } }
protected virtual void Authenticate(LibAuthenticationEventArgs e) { if (this.OnAuthenticate != null) { this.OnAuthenticate(this, e); } if (e.Context.User == null) { if (e.User != null) { e.Context.User = e.User; } else { bool fromCookie = true; ILibAuthenticationTicket ticket = LibAuthentication.ExtractTicketFromCookie(ref fromCookie); if (ticket == null) { LibAuthentication.RedirectLogin(e.Context); return; } else { LibAuthentication.PrepareTicket(ticket); e.Context.User = new LibPrincipal(new LibIdentity(ticket)); HttpCookie cookie = LibAuthentication.PrepareCookie(ticket, fromCookie); e.Context.Response.Cookies.Remove(cookie.Name); e.Context.Response.Cookies.Add(cookie); } } } }