Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public UserInfo(string login)
- {
- LdapConnection con = new LdapConnection(new LdapDirectoryIdentifier("ldap.vsb.cz", 636));
- con.SessionOptions.SecureSocketLayer = true;
- con.AuthType = AuthType.Anonymous;
- using (con)
- {
- try
- {
- SearchRequest request = new SearchRequest(
- "",
- String.Format("(&(objectClass=Person)(uid={0}))", login),
- System.DirectoryServices.Protocols.SearchScope.Subtree
- );
- SearchResponse response = (SearchResponse)con.SendRequest(request);
- if (response.Entries.Count == 0)
- {
- // NO
- }
- else
- {
- SearchResultEntry entry = response.Entries[0];
- string dn = entry.DistinguishedName;
- string path = "LDAP://ldap.vsb.cz:389/" + dn;
- DirectoryEntry dentry = new DirectoryEntry(path);
- dentry.AuthenticationType = AuthenticationTypes.Anonymous;
- DirectorySearcher search = new DirectorySearcher(dentry);
- SearchResult result = search.FindOne();
- this.Login = result.Properties["cn"][0].ToString();
- this.FName = result.Properties["givenname"][0].ToString();
- this.LName = result.Properties["sn"][0].ToString();
- this.Email = result.Properties["mail"][0].ToString();
- }
- }
- catch
- {
- this.Login = null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement