Ejemplo n.º 1
0
        /// <summary>
        /// Initializes data that might not be available when the constructor is called.
        /// </summary>
        /// <param name="requestContext">The HTTP context and route data.</param>
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);

            this.userState = new UserState();
            if (this.User.Identity != null && this.User.Identity is FormsIdentity)
            {
                this.userState.FromString(((FormsIdentity)this.User.Identity).Ticket.UserData);
            }

            this.ViewData["UserState"] = this.userState;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Issues the auth ticket.
        /// </summary>
        /// <param name="userState">State of the user.</param>
        /// <param name="rememberMe">if set to <c>true</c> [remember me].</param>
        private void IssueAuthTicket(UserState userState, bool rememberMe)
        {
            // create auth ticket
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, userState.DisplayName, DateTime.Now, DateTime.Now.AddYears(1), rememberMe, userState.ToString());

            // encrypt ticket
            string ticketString = FormsAuthentication.Encrypt(ticket);

            // create cookie
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticketString);
            if (rememberMe)
            {
                // set expiration
                cookie.Expires = DateTime.Now.AddYears(1);
            }

            // add cokie to users machine
            HttpContext.Response.Cookies.Add(cookie);
        }