Exemplo n.º 1
0
        private HttpCookie CreateAuthCookie(UserDataCookie dataCookie)
        {
            var expiration   = DateTime.Now.AddMinutes(_settings.TimeOut);
            var ispersistent = false;

            var json = new JavaScriptSerializer().Serialize(dataCookie);

            if (dataCookie.RememberMe)
            {
                ispersistent = true;
                expiration   = DateTime.Now.AddYears(1);
            }

            var ticket = new FormsAuthenticationTicket(4, dataCookie.Login, DateTime.Now, expiration, ispersistent, json);

            var encryptedTicket = FormsAuthentication.Encrypt(ticket);

            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
            {
                Expires  = expiration,
                Secure   = FormsAuthentication.RequireSSL,
                HttpOnly = true
            };

            return(cookie);
        }
Exemplo n.º 2
0
        private void SetAuthCookie(UserDataCookie dataCookie, string[] roles)
        {
            dataCookie.IP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

            dataCookie.Roles = roles;

            var ticket = CreateAuthCookie(dataCookie);

            HttpContext.Current.Response.Cookies.Add(ticket);
        }