Exemple #1
0
        public static void GetAuthenticationTicket(UserInfo info, bool rememberMe)
        {
            FormsAuthentication.Initialize();
            StringBuilder sb = new StringBuilder(200);

            sb.Append(Encryption.Encrypt(info.UserId.ToString()));
            sb.Append("_!_");
            sb.Append(Encryption.Encrypt(info.FullName));
            //sb.Append("_!_");
            //sb.Append(Encryption.Encrypt(info.IsOrganization.ToString()));
            sb.Append("_!_");
            sb.Append(Encryption.Encrypt(info.Login.ToString()));
            HttpCookie ck;

            FormsAuthenticationTicket tkt = new FormsAuthenticationTicket(1, sb.ToString(), DateTime.Now, DateTime.Now.AddDays(5), rememberMe, "");
            string cookiestr = FormsAuthentication.Encrypt(tkt);

            ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
            if (rememberMe)
            {
                ck.Expires = tkt.Expiration;
            }
            ck.Path   = FormsAuthentication.FormsCookiePath;
            ck.Domain = SiteCookie.DomainCookie;//HttpContext.Current.Request.Url.Host;

            if (HttpContext.Current.Request.Url.Host.ToLower().Equals(UserDomain))
            {
                ck.Domain = UserInfo.UserDomain;
            }
            else if (HttpContext.Current.Request.Url.Host.ToLower().Equals("stage." + UserDomain))
            {
                ck.Domain = "stage." + UserDomain;
            }
            else
            {
                ck.Domain = SiteCookie.DomainCookie;
            }

            HttpContext.Current.Response.Cookies.Add(ck);
            SiteCookie.Update(SiteCookieName.RandomUserCrypId, System.Guid.NewGuid().ToString(), 30);
        }