T
Ted Vreeland via DotNetMonster.com
Hi Folks,
I've got a intranet ASP.NET page that takes a user id (e.g. 'DoeJ') passed in and attempts to get the First and Last name of the user from the Active Directory. I'm running into some issues and am hoping someone can look at it and tell me whats wrong. I've gotten several different errors (Referal from server, unspecified error, etc). Any assistance would be greatly appreciated.
Best Regards,
Ted
CODE:
-----------------
DirectoryEntry _de = new DirectoryEntry( "LDAP://rootDSE" );
string _DomainPath = _de.Properties["DefaultNamingContext"][0].ToString();
DirectoryEntry _root = new DirectoryEntry( _DomainPath );
DirectorySearcher _src = new DirectorySearcher( _root);
_src.Filter = "(&(objectCategory=Person)(SAMAccountName=" + Request["DomainId"] + ")";
_src.PropertiesToLoad.Add( "givenname" );
_src.PropertiesToLoad.Add( "sn" );
_src.PropertiesToLoad.Add( "mail" );
SearchResult _res = _src.FindOne();
firstName = _res.Properties["givenname"][0].ToString();
lastName = _res.Properties["sn"][0].ToString();
I've got a intranet ASP.NET page that takes a user id (e.g. 'DoeJ') passed in and attempts to get the First and Last name of the user from the Active Directory. I'm running into some issues and am hoping someone can look at it and tell me whats wrong. I've gotten several different errors (Referal from server, unspecified error, etc). Any assistance would be greatly appreciated.
Best Regards,
Ted
CODE:
-----------------
DirectoryEntry _de = new DirectoryEntry( "LDAP://rootDSE" );
string _DomainPath = _de.Properties["DefaultNamingContext"][0].ToString();
DirectoryEntry _root = new DirectoryEntry( _DomainPath );
DirectorySearcher _src = new DirectorySearcher( _root);
_src.Filter = "(&(objectCategory=Person)(SAMAccountName=" + Request["DomainId"] + ")";
_src.PropertiesToLoad.Add( "givenname" );
_src.PropertiesToLoad.Add( "sn" );
_src.PropertiesToLoad.Add( "mail" );
SearchResult _res = _src.FindOne();
firstName = _res.Properties["givenname"][0].ToString();
lastName = _res.Properties["sn"][0].ToString();