示例#1
0
        protected void Application_AuthenticateRequest(Object sender, EventArgs e)
        {
            if (Request.IsAuthenticated == true)
            {
                string[] grupos;
                // Create the roles cookie if it doesn't exist yet for this session.
                if ((Request.Cookies["Portalgrupos"] == null) || (Request.Cookies["Portalgrupos"].Value == ""))
                {
                    // Get roles from UserRoles table, and add to cookie
                    grupos = UsuariosBD.ObtenerGrupos(User.Identity.Name);

                    // Create a string to persist the roles
                    string grupoStr = "";
                    foreach (string grupo in grupos)
                    {
                        grupoStr += grupo;
                        grupoStr += ";";
                    }

                    // Create a cookie authentication ticket.
                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                        1,                                                      // version
                        Context.User.Identity.Name,                             // user name
                        DateTime.Now,                                           // issue time
                        DateTime.Now.AddHours(1),                               // expires every hour
                        false,                                                  // don't persist cookie
                        grupoStr                                                // roles
                        );

                    // Encrypt the ticket
                    string cookieStr = FormsAuthentication.Encrypt(ticket);
                    // Send the cookie to the client
                    Response.Cookies["aplicaciongrupos"].Value   = cookieStr;
                    Response.Cookies["aplicaciongrupos"].Path    = "/";
                    Response.Cookies["aplicaciongrupos"].Expires = DateTime.Now.AddMinutes(1);
                }
                else
                {
                    // Get roles from roles cookie
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Context.Request.Cookies["Portalgrupos"].Value);

                    //convert the string representation of the role data into a string array
                    ArrayList gruposUsuario = new ArrayList();

                    foreach (string grupo in ticket.UserData.Split(new char[] { ';' }))
                    {
                        gruposUsuario.Add(grupo);
                    }

                    grupos = (String[])gruposUsuario.ToArray(typeof(string));
                }

                // Add our own custom principal to the request containing the roles in the auth ticket
                Context.User = new GenericPrincipal(Context.User.Identity, grupos);
            }
        }
        public static string ObtenerNombre(string Usuario)
        {
            IDataReader Datos = UsuariosBD.Obtener(Usuario);

            string Nombre = string.Empty;

            if (Datos.Read())
            {
                Nombre += (string)Datos["Nombre"];
                Nombre += " " + (string)Datos["Apellido"];
            }
            Datos.Close();
            return(Nombre);
        }
示例#3
0
        public static string ObtenerTemaPortal()
        {
            string Tema = ConfigurationSettings.AppSettings["PortalTema"];

            IDataReader usuario = UsuariosBD.Obtener(HttpContext.Current.User.Identity.Name);

            if (usuario.Read())
            {
                Tema = usuario["Tema"].ToString();
            }

            usuario.Close();

            return(Tema);
        }
        public static string[] ObtenerGrupos(string Usuario)
        {
            IDataReader Datos = UsuariosBD.ObtenerGruposReader(Usuario);

            ArrayList gruposUsuario = new ArrayList();

            while (Datos.Read())
            {
                gruposUsuario.Add(Datos["Nombre"]);
            }

            Datos.Close();

            return((string[])gruposUsuario.ToArray(typeof(string)));
        }