private static void OnAuthenticateRequest(object sender, EventArgs e)
        {
            var application = (HttpApplication)sender;

            HttpContext context = application.Context;

            if (context.User != null && context.User.Identity.IsAuthenticated)
            {
                return;
            }

            string cookieName = "webrunes";//FormsAuthentication.FormsCookieName;

            HttpCookie cookie = application.Request.Cookies[cookieName];

            if (cookie == null)
            {
                return;
            }
            try
            {
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
                var identity  = new CustomIdentity(AccountCollectionEntry.Deserialize(ticket.UserData), ticket.Name);
                var principal = new GenericPrincipal(identity, identity.GetRoles());
                context.User            = principal;
                Thread.CurrentPrincipal = principal;
            }
            catch
            {
            }
        }
        public void DeleteUserFromContext(string id)
        {
            HttpCookie currentUserCookie     = _context.Request.Cookies["webrunes"];
            FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(currentUserCookie.Value);
            var collectionentry = AccountCollectionEntry.Deserialize(ticket.UserData);

            collectionentry.DeleteBy(id);
            collectionentry.CurrentAccountId = null;

            var authTicket = new FormsAuthenticationTicket(1,
                                                           "",
                                                           DateTime.Now,
                                                           DateTime.Now.AddDays(-1),
                                                           false,
                                                           AccountCollectionEntry.Serialize(collectionentry));

            UpdateContextResponse(authTicket, collectionentry);
        }
        public bool SignOut(IUserService userService)
        {
            if (!_context.User.Identity.IsAuthenticated)
            {
                return(false);
            }
            HttpCookie currentUserCookie = _context.Request.Cookies["webrunes"];

            FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(currentUserCookie.Value);
            var collectionentry = AccountCollectionEntry.Deserialize(ticket.UserData);

            collectionentry.CurrentAccountId = null;

            var authTicket = new FormsAuthenticationTicket(1,
                                                           "",
                                                           DateTime.Now,
                                                           DateTime.Now.AddDays(-1),
                                                           false,
                                                           AccountCollectionEntry.Serialize(collectionentry));

            UpdateContextResponse(authTicket, collectionentry);
            return(true);
        }