Q
活動目錄助手類
5
A
回答
10
在.NET 3.5中,你想在System.DirectoryServices.AccountManagement看看。對於較早的版本,System.DirectoryServices版本具有您所需要的版本,但它的工作稍微多一點。
using (var context = new PrincipalContext(ContextType.Domain))
{
var valid = context.ValidateCredentials(username, password);
using (var user = UserPrincipal.FindByIdentity(context,
IdentityType.SamAccountName,
username))
{
var groups = user.GetAuthorizationGroups();
}
}
2
System.DirectoryServices.ActiveDirectory命名空間
http://msdn.microsoft.com/en-us/library/system.directoryservices.activedirectory.aspx
+1
這確實是與交互和管理的ActiveDirectory的行政方面 - 架構,服務器,網站,森林等。用戶相關的組件位於不同的名稱空間中。 – tvanfosson 2009-06-12 00:29:40
+0
感謝您的更正,正確注意到 – 2009-06-12 00:37:07
3
這裏是我一直在使用一些示例代碼:
using System.DirectoryServices;
public static string GetProperty(SearchResult searchResult,
string PropertyName)
{
if (searchResult.Properties.Contains(PropertyName))
return searchResult.Properties[PropertyName][0].ToString();
else
return string.Empty;
}
public MyCustomADRecord Login(string UserName, string Password)
{
string adPath = "LDAP://www.YourCompany.com/DC=YourCompany,DC=Com";
DirectorySearcher mySearcher;
SearchResult resEnt;
DirectoryEntry de = new DirectoryEntry(adPath, UserName, Password,
AuthenticationTypes.Secure);
mySearcher = new DirectorySearcher(de);
string adFilter = "(sAMAccountName=" + UserName + ")";
mySearcher.Filter = adFilter;
resEnt = mySearcher.FindOne();
return new MyCustomADRecord()
{
UserName = GetProperty(resEnt, "sAMAccountName"),
GUID = resEnt.GetDirectoryEntry().NativeGuid.ToString(),
DisplayName = GetProperty(resEnt, "displayName"),
FirstName = GetProperty(resEnt, "givenName"),
MiddleName = GetProperty(resEnt, "initials"),
LastName = GetProperty(resEnt, "sn"),
Company = GetProperty(resEnt, "company"),
JobTitle = GetProperty(resEnt, "title"),
Email = GetProperty(resEnt, "mail"),
Phone = GetProperty(resEnt, "telephoneNumber"),
ExtensionAttribute1 = GetProperty(resEnt, "extensionAttribute1")
};
}
相關問題
- 1. 導航助手活動記錄
- 2. 活動目錄
- 3. 笨活動記錄幫助
- 4. 笨活動記錄幫助
- 5. 助手類 - 錯誤無法啓動活動ComponentInfo:
- 6. 將活動類添加到目錄
- 7. 活動目錄GUID
- 8. 活動目錄GUID
- 9. 登錄到活動目錄
- 10. azure活動目錄登錄
- 11. Azure活動目錄活動ActAs WCF
- 12. 手動構建活動記錄對象
- 13. 目錄手錶類(.NET)
- 14. Django項目助手函數/類
- 15. 活動目錄屬性
- 16. iPhone和Windows活動目錄
- 17. Powershell腳本活動目錄
- 18. Thread.CurrentPrincipal.Identity和活動目錄
- 19. 活動目錄到LDIF OpenLDAP
- 20. 活動目錄WCF服務
- 21. 活動目錄LDS異常
- 22. 活動目錄監控
- 23. Glassfish JAAS活動目錄
- 24. 活動目錄和LDAP庫
- 25. 活動目錄認證
- 26. Umbraco:活動目錄執行
- 27. 幫助需要跟蹤活動目錄更改
- 28. 疑難解答幫助:活動目錄綁定失敗
- 29. 使用sharedpreference幫助登錄活動
- 30. MySQL的 - 笨活動記錄幫助
我正在開發一臺筆記本電腦,而不是域的一部分。我可以將此類請求傳遞給AD嗎? – 2009-06-12 00:40:07