Example #1
0
        private void Authenticate()
        {
            var context = HttpContext.Current;

            var actualCookieName = CustomFormsAuthentication.GetActualCookieName();


            var ticket = CustomFormsAuthentication.ExtractTicketFromCookie(actualCookieName);

            if (ticket == null || ticket.Expired)
            {
                return;
            }

            CustomFormsAuthentication.InitializeUserContext(ticket);

            var newTicket = ticket;

            if (CustomFormsAuthentication.SlidingExpiration)
            {
                newTicket = FormsAuthentication.RenewTicketIfOld(ticket);
            }

            if (newTicket != ticket)
            {
                var cookie = CustomFormsAuthentication.GetAuthCookie(actualCookieName, newTicket, true);

                context.Response.Cookies.Remove(cookie.Name);
                context.Response.Cookies.Add(cookie);
            }
        }
Example #2
0
 private void ContextOnEndRequest(object sender, EventArgs eventArgs)
 {
     if (((HttpApplication)sender).Context.Response.StatusCode == (int)HttpStatusCode.Unauthorized)
     {
         CustomFormsAuthentication.RedirectToLoginPage();
     }
 }
Example #3
0
        private void ContextOnAuthenticateRequest(object sender, EventArgs eventArgs)
        {
            var isValidWebResourceRequest = IsValidWebResourceRequest();

            if (isValidWebResourceRequest == false)
            {
                Authenticate();
            }

            HttpContext.Current.SkipAuthorization = isValidWebResourceRequest || CustomFormsAuthentication.IsLoginPage();

            if (HttpContext.Current.User == null)
            {
                HttpContext.Current.User = new GenericPrincipal(new GenericIdentity(String.Empty), null);
            }
        }