Beispiel #1
0
        public bool IsAdminUser(string username)
        {
            //FOR WINDOWS AUTHENTICATION....
            var UseActiveDirectory = System.Configuration.ConfigurationManager.AppSettings["UseActiveDirectory"]; //CommonFunction.Instance.UseActiveDirectory();

            if (Convert.ToBoolean(UseActiveDirectory))
            {
                //var adl = new ActiveDirectoryLookup(this.Identity);
                //var adminString = System.Configuration.ConfigurationManager.AppSettings["AdministratorRoles"]; //CommonFunction.Instance.AdministratorRoles();
                //var admins = adminString.Split(',', ';');
                //return adl.GetRoles().Any(r => admins.Contains(r));
                var UseActiveDirectoryRole = ConfigurationManager.AppSettings["UseActiveDirectoryRole"];
                if (Convert.ToBoolean(UseActiveDirectoryRole))
                {
                    var adl         = new ActiveDirectoryLookup(this.Identity);
                    var adminString = System.Configuration.ConfigurationManager.AppSettings["AdministratorRoles"];
                    var admins      = adminString.Split(',', ';');
                    return(adl.GetRoles().Any(r => admins.Contains(r)));
                }
                else
                {
                    var DomainName  = System.Configuration.ConfigurationManager.AppSettings["DomainName"];
                    var adminString = System.Configuration.ConfigurationManager.AppSettings["AdministratorRoles"];
                    CustomRoleProvider RoleProvider = new CustomRoleProvider();
                    return(RoleProvider.IsUserInRole(username, adminString));
                }
            }
            else
            {
                var adminString = System.Configuration.ConfigurationManager.AppSettings["AdministratorRoles"]; //CommonFunction.Instance.AdministratorRoles();

                CustomRoleProvider RoleProvider = new CustomRoleProvider();
                return(RoleProvider.IsUserInRole(username, adminString));
            }
        }
Beispiel #2
0
        public IEnumerable <string> GetRoles()
        {
            //FOR WINDOWS AUTHENTICATION....
            var UseActiveDirectory = System.Configuration.ConfigurationManager.AppSettings["UseActiveDirectory"]; //CommonFunction.Instance.UseActiveDirectory();

            if (Convert.ToBoolean(UseActiveDirectory))
            {
                //var adl = new ActiveDirectoryLookup(this.Identity);
                //return adl.GetRoles();
                var UseActiveDirectoryRole = System.Configuration.ConfigurationManager.AppSettings["UseActiveDirectoryRole"];
                if (Convert.ToBoolean(UseActiveDirectoryRole))
                {
                    var adl = new ActiveDirectoryLookup(this.Identity);
                    return(adl.GetRoles());
                }
                else
                {
                    var DomainName = System.Configuration.ConfigurationManager.AppSettings["DomainName"];
                    CustomRoleProvider RoleProvider = new CustomRoleProvider();
                    string             usrname      = this.Name.Replace(DomainName.ToUpper() + "\\", "").Trim();
                    return(RoleProvider.GetRolesForUser(usrname));
                }
            }
            else
            {
                CustomRoleProvider RoleProvider = new CustomRoleProvider();
                return(RoleProvider.GetRolesForUser(((IIdentity)this.Identity).Name));
            }
        }
Beispiel #3
0
        public bool IsAdminUser()
        {
            var adminString = System.Configuration.ConfigurationManager.AppSettings["AdministratorRoles"]; //CommonFunction.Instance.AdministratorRoles();

            CustomRoleProvider RoleProvider = new CustomRoleProvider();

            return(RoleProvider.IsUserInRole(this.Name, adminString));
        }
        public string getUserEmailidsFromRoles(string[] roles)
        {
            string result = "";

            if (roles[0] == "")
            {
                return("");
            }
            foreach (var item in roles)
            {
                string[]           userIds = { };
                CustomRoleProvider x       = new CustomRoleProvider();
                userIds = x.GetUsersInRole(item);
                foreach (var userId in userIds)
                {
                    var objuser = usercontext.Users.FirstOrDefault(p => p.Id == userId);
                    if (objuser != null && !string.IsNullOrEmpty(objuser.Email))
                    {
                        result += objuser != null ? objuser.Email + "," : "";
                    }
                }
            }
            return(result);
        }
Beispiel #5
0
        public IEnumerable <string> GetRoles()
        {
            CustomRoleProvider RoleProvider = new CustomRoleProvider();

            return(RoleProvider.GetRolesForUser(this.Name));
        }