0
A
回答
1
添加「公司」到的DirectorySearcher的PropertiesToLoad屬性:
var ds = new DirectorySearcher(ldapRoot);
ds.PropertiesToLoad.Add("company");
var directoryEntry = ds.FindOne();
...
Console.WriteLine(directoryEntry.Properties["company"]);
0
下面是類我幾年前寫的拉本信息。
我還沒有深入到代碼多年,所以它必須工作得很好。
希望你能從中獲得一些用處。
class ADProperties {
public const string OBJECTCLASS = "objectClass";
public const string CONTAINERNAME = "cn";
public const string LASTNAME = "sn";
public const string COUNTRYNOTATION = "c";
public const string CITY = "l";
public const string STATE = "st";
public const string TITLE = "title";
public const string POSTALCODE = "postalCode";
public const string PHYSICALDELIVERYOFFICENAME = "physicalDeliveryOfficeName";
public const string FIRSTNAME = "givenName";
public const string MIDDLENAME = "initials";
public const string DISTINGUISHEDNAME = "distinguishedName";
public const string INSTANCETYPE = "instanceType";
public const string WHENCREATED = "whenCreated";
public const string WHENCHANGED = "whenChanged";
public const string DISPLAYNAME = "displayName";
public const string USNCREATED = "uSNCreated";
public const string MEMBEROF = "memberOf";
public const string USNCHANGED = "uSNChanged";
public const string COUNTRY = "co";
public const string DEPARTMENT = "department";
public const string COMPANY = "company";
public const string PROXYADDRESSES = "proxyAddresses";
public const string STREETADDRESS = "streetAddress";
public const string DIRECTREPORTS = "directReports";
public const string NAME = "name";
public const string OBJECTGUID = "objectGUID";
public const string USERACCOUNTCONTROL = "userAccountControl";
public const string BADPWDCOUNT = "badPwdCount";
public const string CODEPAGE = "codePage";
public const string COUNTRYCODE = "countryCode";
public const string BADPASSWORDTIME = "badPasswordTime";
public const string LASTLOGOFF = "lastLogoff";
public const string LASTLOGON = "lastLogon";
public const string PWDLASTSET = "pwdLastSet";
public const string PRIMARYGROUPID = "primaryGroupID";
public const string OBJECTSID = "objectSid";
public const string ADMINCOUNT = "adminCount";
public const string ACCOUNTEXPIRES = "accountExpires";
public const string LOGONCOUNT = "logonCount";
public const string LOGINNAME = "sAMAccountName";
public const string SAMACCOUNTTYPE = "sAMAccountType";
public const string SHOWINADDRESSBOOK = "showInAddressBook";
public const string LEGACYEXCHANGEDN = "legacyExchangeDN";
public const string USERPRINCIPALNAME = "userPrincipalName";
public const string EXTENSION = "ipPhone";
public const string SERVICEPRINCIPALNAME = "servicePrincipalName";
public const string OBJECTCATEGORY = "objectCategory";
public const string DSCOREPROPAGATIONDATA = "dSCorePropagationData";
public const string LASTLOGONTIMESTAMP = "lastLogonTimestamp";
public const string EMAILADDRESS = "mail";
public const string MANAGER = "manager";
public const string MOBILE = "mobile";
public const string PAGER = "pager";
public const string FAX = "facsimileTelephoneNumber";
public const string HOMEPHONE = "homePhone";
public const string MSEXCHUSERACCOUNTCONTROL = "msExchUserAccountControl";
public const string MDBUSEDEFAULTS = "mDBUseDefaults";
public const string MSEXCHMAILBOXSECURITYDESCRIPTOR = "msExchMailboxSecurityDescriptor";
public const string HOMEMDB = "homeMDB";
public const string MSEXCHPOLICIESINCLUDED = "msExchPoliciesIncluded";
public const string HOMEMTA = "homeMTA";
public const string MSEXCHRECIPIENTTYPEDETAILS = "msExchRecipientTypeDetails";
public const string MAILNICKNAME = "mailNickname";
public const string MSEXCHHOMESERVERNAME = "msExchHomeServerName";
public const string MSEXCHVERSION = "msExchVersion";
public const string MSEXCHRECIPIENTDISPLAYTYPE = "msExchRecipientDisplayType";
public const string MSEXCHMAILBOXGUID = "msExchMailboxGuid";
public const string NTSECURITYDESCRIPTOR = "nTSecurityDescriptor";
}
public class ADUser {
#region ' Properties '
public string City { get; private set; }
public string Company { get; private set; }
public string Country { get; private set; }
public string Department { get; private set; }
public string EmailAddress { get; private set; }
public string Extension { get; private set; }
public string Fax { get; private set; }
public string FirstName { get; private set; }
public string HomePhone { get; private set; }
public string LastName { get; private set; }
public string UserName { get; private set; }
public string LoginNameWithDomain { get; private set; }
public string FullName {
get {
if (!String.IsNullOrEmpty(FirstName)) {
if (!String.IsNullOrEmpty(LastName)) {
return string.Format("{0} {1}", FirstName, LastName);
} else {
return FirstName;
}
} else if (!String.IsNullOrEmpty(LastName)) {
return LastName;
} else {
return null;
}
}
}
public string MiddleName { get; private set; }
public string Mobile { get; private set; }
public string PostalCode { get; private set; }
public string StreetAddress { get; private set; }
public string State { get; private set; }
public string Title { get; private set; }
#endregion
private ADUser(DirectoryEntry directoryUser) {
FirstName = GetProperty(directoryUser, ADProperties.FIRSTNAME);
MiddleName = GetProperty(directoryUser, ADProperties.MIDDLENAME);
LastName = GetProperty(directoryUser, ADProperties.LASTNAME);
UserName = GetProperty(directoryUser, ADProperties.LOGINNAME);
string userPrincipalName = GetProperty(directoryUser, ADProperties.USERPRINCIPALNAME);
string domainAddress = (!String.IsNullOrEmpty(userPrincipalName)) ? userPrincipalName.Split('@')[1] : null;
string domainName = (!String.IsNullOrEmpty(domainAddress)) ? domainAddress.Split('.')[0] : null;
LoginNameWithDomain = String.Format(@"{0}\{1}", domainName, UserName);
StreetAddress = GetProperty(directoryUser, ADProperties.STREETADDRESS);
City = GetProperty(directoryUser, ADProperties.CITY);
State = GetProperty(directoryUser, ADProperties.STATE);
PostalCode = GetProperty(directoryUser, ADProperties.POSTALCODE);
Country = GetProperty(directoryUser, ADProperties.COUNTRY);
Company = GetProperty(directoryUser, ADProperties.COMPANY);
Department = GetProperty(directoryUser, ADProperties.DEPARTMENT);
HomePhone = GetProperty(directoryUser, ADProperties.HOMEPHONE);
Extension = GetProperty(directoryUser, ADProperties.EXTENSION);
Mobile = GetProperty(directoryUser, ADProperties.MOBILE);
Fax = GetProperty(directoryUser, ADProperties.FAX);
EmailAddress = GetProperty(directoryUser, ADProperties.EMAILADDRESS);
Title = GetProperty(directoryUser, ADProperties.TITLE);
}
private static string GetProperty(DirectoryEntry userDetail, string propertyName) {
if (userDetail.Properties.Contains(propertyName)) {
return userDetail.Properties[propertyName][0].ToString();
} else {
return null;
}
}
public static ADUser GetUser(DirectoryEntry directoryUser) {
return new ADUser(directoryUser);
}
public override string ToString() {
if (!String.IsNullOrEmpty(EmailAddress)) {
return string.Format("{0} <{1}>", FullName, EmailAddress);
} else {
return FullName;
}
}
}
相關問題
- 1. Google API獲取公司/組織名稱
- 2. 獲取公共領域?
- 3. 在WebLogic中組織領域
- 4. SQL - 從獲取具有公共領域
- 5. TFS組織在大公司(TFS 2012)
- 6. ASP.Net中的組織領域MVC 5
- 7. 獲取領域
- 8. 獲取領域
- 9. 從域名獲取組織名稱
- 10. Updata公司計算領域的「AFTER INSERT」觸發
- 11. 有限公司外場的選擇基於其他領域
- 12. 如何從Linkedin獲取公司ID PHP中的公司URL?
- 13. 獲取獨特的領域
- 14. 從同一公司網站的不同域獲取Cookie
- 15. 獲取特定區域內的所有公司地理編碼
- 16. 公司領域不適用於X.M.L.報告
- 17. 獲取所有領域
- 18. 無法獲取XML領域
- 19. 獲取公司的歷史股價
- 20. odoo重複的公司獲取錯誤
- 21. 獲取子公司netsuite的列表
- 22. Gradle公司的母公司
- 23. 無法獲取我公司中某些羣組的屬性
- 24. 如何使用新的Basecamp API獲取組和公司?
- 25. 更新iOS開發人員計劃類型(公司/組織)
- 26. 更改Apple開發人員公司/組織名稱
- 27. 公共房屋或公共領域?
- 28. 如何從Google獲取公司信息?
- 29. iPhone聯繫人 - 獲取公司名稱
- 30. 從Linkedin獲取公司名稱api
如果您已經檢索到directoryEntry中的公司屬性,這將起作用。如果您使用尚未加載公司屬性的DirectoryEntry對象調用ADUser構造函數,則看起來它將返回null。 – Jaymz 2012-04-03 14:41:57
嗯...也許。我還有另一堂課與這兩個小班合作,但我的另一堂課充滿了OP可能不想要的個人公司特定信息。我會把它留在這裏作爲參考,但承認你的版本是更好的答案。 – jp2code 2012-04-03 14:44:35
感謝Jaymz和jp2code, 我製作了GetProperty方法並開始工作。 我想知道是否有可能尋找通過價值的公司,而不是比較價值? 因爲這樣,我必須比較所有用戶的值,直到比較返回true。 Regards, Víctor – 2012-04-03 21:21:31