示例#1
0
        /// <summary>
        /// Cria um ticket com as informações do usuario
        /// </summary>
        /// <param name="userId">codigo do usuario</param>
        /// <param name="username">nome do usuario</param>
        /// <param name="isPersistent">true se o cookie será armazenado em um cookie persistente 
        ///                             (salvo em browser Sessions), caso contrário, 
        ///                             false o cookie é armazenado na URL, este valor É ignorado.
        /// </param>
        /// <param name="roles">Os dados específicos do usuário para ser armazenado com o cookie.(roles)</param>
        /// <param name="expiration">A data local e hora em que o cookie expira.</param>
        /// <returns>cookie criptografado</returns>
        public static string CreateTicket(string username, bool isPersistent, User userData, DateTime expiration)
        {
            var userSerialize = new JavaScriptSerializer().Serialize(userData);

            FormsAuthentication.Initialize();

            // Cria o ticket de autenticação
            var ticket = new FormsAuthenticationTicket(
                                                        1,
                                                        username,
                                                        DateTime.Now,
                                                        expiration,
                                                        isPersistent,
                                                        userSerialize,
                                                        FormsAuthentication.FormsCookiePath
                                                       );

            // Criptografa o ticket
            string hash = FormsAuthentication.Encrypt(ticket);

            // Cria o cookie
            System.Web.HttpCookie ticketCookie = new HttpCookie("Ticket", TicketCompress(hash));
            ticketCookie.Expires = DateTime.Now.AddDays(3);
            HttpContext.Current.Response.Cookies.Add(ticketCookie);

            return hash;
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the User EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUser(User user)
 {
     base.AddObject("User", user);
 }
 /// <summary>
 /// Create a new User object.
 /// </summary>
 /// <param name="idUser">Initial value of the idUser property.</param>
 /// <param name="nameUser">Initial value of the nameUser property.</param>
 /// <param name="loginUser">Initial value of the loginUser property.</param>
 /// <param name="passwordUser">Initial value of the passwordUser property.</param>
 public static User CreateUser(global::System.Int32 idUser, global::System.String nameUser, global::System.String loginUser, global::System.String passwordUser)
 {
     User user = new User();
     user.idUser = idUser;
     user.nameUser = nameUser;
     user.loginUser = loginUser;
     user.passwordUser = passwordUser;
     return user;
 }