public bool Pertenece(string grupoLdap,string usuario, string pwd,string usuarioLdap,string pwdLdap) { string pathGrupo; string GrupoUsuario; DirectoryEntry entrada; DirectorySearcher buscador; SearchResult resultado; try { entrada = new DirectoryEntry(pPath,usuarioLdap,pwdLdap); buscador = new DirectorySearcher(entrada); buscador.Filter = "(SAMAccountName=" + usuario + ")"; buscador.PropertiesToLoad.Add("memberOf"); resultado = buscador.FindOne(); for( int contador = 0; contador < resultado.Properties["memberOf".Count; contador++) { grupoLdap=grupoLdap.ToUpper() + ","; pathGrupo = (String)resultado.Properties["memberOf"][contador]; GrupoUsuario= pathGrupo.ToUpper().Substring(3,grupoLdap.Length); if (GrupoUsuario==grupoLdap) return true; } } catch (Exception ex) { pError=ex.Message; return false; } return false; } Fuente 2. |