Boletín mugperu Digital - Julio 2009!
  Search 
Thursday, February 09, 2012 ..:: Foros de Discusión ::.. Register  Login
Foros MUGPERU Minimize
Subject: asp.net page que lee el Active Directory
Prev Next
You are not authorized to post a reply.

Author Messages
EMUNOZ
Posts:15

05/03/2009 05:22 PM  

Hola, alguien tiene codigo ejemplo como acceder al Active Directory desde un asp.net web form?

 

saludos,

 

rcrbalcazar
Posts:130

03/04/2009 09:03 PM  
Para obtener data del AD desde una aplicacion web debes utilizar el namespace System.DirectoryServices por ejemplo con la siguiente funcion puedes obtener algun atributo de un usuario en el AD

public static string getAttribute(string path, string atributo, string usuario, string atributoBusqueda)
{
string valor = "";
DirectoryEntry dom = new DirectoryEntry(path);
DirectorySearcher searcher = new DirectorySearcher(dom, "(&(objectCategory=person)(objectClass=user)(" + atributoBusqueda + "=" + usuario + "))");
try
{
foreach (SearchResult result in searcher.FindAll())
{
if (result.Properties[atributo].Count > 0)
{
valor = (result.Properties[atributo]Ύ].ToString());
}
else
break;
if (valor.Length > 0)
break;
}
return valor;
}
catch (Exception ex)
{
throw ex;
}
}

la puedes usar de la siguiente manera:
getAttribute("LDAP://DC=MiDominio,DC=com", "sn", "MiLogin", "sAMAccountName")

es decir: buscar en el AD un usuario cuyo sAMAccountname = MiLogin y devolver su sn
sAMAccountName = Login
sn = Nombre

Saludos.

Richard Rodriguez
You are not authorized to post a reply.
Forums > Temas de Interés > Construcción de Aplicaciones Web con ASP.NET > asp.net page que lee el Active Directory



ActiveForums 3.7
        
Copyright 2001-2012 MUGPERU   Terms Of Use  Privacy Statement