Example #1
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        string roles    = string.Empty;


                        using (churchdatabase_userEntities entities = new churchdatabase_userEntities())
                        {
                            user user = entities.users.SingleOrDefault(u => u.UserName == username);
                            user.role = entities.roles.SingleOrDefault(u => u.roleID == user.RoleID);
                            roles     = user.role.Name;
                        }
                        //let us extract the roles from our own custom cookie


                        //Let us set the Pricipal with our user specific details
                        e.User = new System.Security.Principal.GenericPrincipal(
                            new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';'));
                    }
                    catch (Exception ex)
                    {
                        //somehting went wrong
                    }
                }
            }
        }
Example #2
0
 public ELocalProviderRepository()
 {
     this.entities = new churchdatabase_userEntities();
 }