SetAuthCookie Method

Jul 23, 2011 at 5:41 AM

change

        public static void SetAuthCookie(this SystemFormsAuthentication formsAuthentication, HttpResponseBase response, string userName, bool createPersistentCookie, string userData, DateTime? expiresOn = null)
        {
            var cookie = SystemFormsAuthentication.GetAuthCookie(userName, createPersistentCookie);
            var ticket = SystemFormsAuthentication.Decrypt(cookie.Value);
            var newTicket = new FormsAuthenticationTicket(
                ticket.Version,
                ticket.Name,
                ticket.IssueDate,
                expiresOn ?? ticket.Expiration,
                true,
                userData,
                ticket.CookiePath);
            cookie.Value = SystemFormsAuthentication.Encrypt(newTicket);
            cookie.Expires = newTicket.Expiration;
            response.Cookies.Set(cookie);
        }

to

        public static void SetAuthCookie(this SystemFormsAuthentication formsAuthentication, HttpResponseBase response, string userName, bool createPersistentCookie, string userData, DateTime? expiresOn = null)
        {
            var cookie = SystemFormsAuthentication.GetAuthCookie(userName, createPersistentCookie);
            var ticket = SystemFormsAuthentication.Decrypt(cookie.Value);
            var newTicket = new FormsAuthenticationTicket(
                ticket.Version,
                ticket.Name,
                ticket.IssueDate,
                expiresOn ?? ticket.Expiration,
                createPersistentCookie,
                userData,
                ticket.CookiePath);
            cookie.Value = SystemFormsAuthentication.Encrypt(newTicket);
            if (newTicket.IsPersistent)
                cookie.Expires = newTicket.Expiration;
            response.Cookies.Set(cookie);
        }

May 1, 2012 at 7:21 AM

This was raised as an issue and fixed by Neil Campbell, who then sent a pull request. It is now available on NuGet as of build 1.3.0.12 and above.