Tag: directoryservices

如何获取来宾/管理员的本地组名?

题: 我使用http://support.microsoft.com/kb/306273上的代码 添加Windows用户。 问题是我需要将用户添加到组中,但组名已本地化。 例如,MS-example使用英文计算机,这意味着您可以像这样获取访客组:grp = AD.Children.Find(“Guests”,“group”) 但是在非英语计算机上,“访客”组名是本地化的,例如在我的德语操作系统上,来宾的组名是“Gäste”。 这意味着支持示例在我的计算机上运行我需要将该行更改为grp = AD.Children.Find(“Gäste”,“group”) 然后它工作。 现在,如果操作系统是任何其他语言,我如何找到访客用户的名称? 或者如何从sid获取来宾用户名? 注意:.NET 2.0,而不是3.0或3.5

使用DirectoryServices.AccountManagement从OU获取组

我想使用AccountManagement列出组织单位中的所有组。 以下代码段与DirectoryServices一起使用,但我必须在结果中使用DirectoryEntry路径实现GroupPrincipal(这感觉就像一个脏修复)。 DirectoryEntry root = new DirectoryEntry(“LDAP://OU=Marketing,OU=Operations,OU=Applications,DC=mycompany,DC=local”) DirectorySearcher ds = new DirectorySearcher(root); ds.Filter = “(objectCategory=group)”; SearchResultCollection results = ds.FindAll(); 有人有想法吗? 谢谢!

如何在ActiveDirectory和.NET 3.5中确定用户所属的所有组(包括嵌套组)

我有一个使用ActiveDirecotry授权的应用程序,并且已经决定它需要支持嵌套的AD组,例如: MAIN_AD_GROUP | |-> SUB_GROUP | |-> User 因此,用户不直接成为MAIN_AD_GROUP的成员。 我希望能够递归地查找用户,搜索嵌套在MAIN_AD_GROUP的组。 主要问题是我使用的是.NET 3.5,并且.NET 3.5中的System.DirectoryServices.AccountManagement存在一个错误,即UserPrincipal.IsMemberOf()方法UserPrincipal.IsMemberOf() 用于超过1500个用户的组 。 所以我不能使用UserPrincipal.IsMemberOf()而不是,我也无法切换到.NET 4。 我用以下函数解决了这个最后一个问题: private bool IsMember(Principal userPrincipal, Principal groupPrincipal) { using (var groups = userPrincipal.GetGroups()) { var isMember = groups.Any(g => g.DistinguishedName == groupPrincipal.DistinguishedName); return isMember; } } 但userPrincipal.GetGroups()仅返回用户是其直接成员的组。 如何使用嵌套组?

确定用户是否在.NET 4.0应用程序的AD组中

我试图确定用户是否是内部ASP.NET 4.0应用程序的Active Directory(AD)组的成员。 在用户不是AD组成员的情况下,下面的代码在最后一行(return语句)上抛出“尝试访问已卸载的appdomain”exception错误。 public static bool IsInADGroup(string userName, string groupName) { var principalContext = new PrincipalContext(ContextType.Domain); UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext, userName); if (userPrincipal == null) return false; GroupPrincipal groupPrincipal = GroupPrincipal.FindByIdentity(principalContext, groupName); if (groupPrincipal == null) return false; return userPrincipal.IsMemberOf(groupPrincipal); } 有关如何修复或其他解决方法的任何想法?

遍历属性时,ActiveDirectory错误0x8000500c

我得到以下代码段( SomeName / SomeDomain在我的代码中包含实际值) var entry = new DirectoryEntry(“LDAP://CN=SomeName,OU=All Groups,dc=SomeDomain,dc=com”); foreach (object property in entry.Properties) { Console.WriteLine(property); } 它为前21个属性打印OK,但随后失败: COMException {“Unknown error (0x8000500c)”} at System.DirectoryServices.PropertyValueCollection.PopulateList() at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName) at System.DirectoryServices.PropertyCollection.PropertyEnumerator.get_Entry() at System.DirectoryServices.PropertyCollection.PropertyEnumerator.get_Current() at ActiveDirectory.Tests.IntegrationTests.ObjectFactoryTests.TestMethod1() in MyTests.cs:line 22 为什么? 我该怎样预防呢? 更新 这是一个失败的自定义属性。 在枚举属性(没有帮助)之前,我尝试使用entry.RefreshCache()和entry.RefreshCache(new[]{“theAttributeName”}) )。 UPDATE2 entry.InvokeGet(“theAttributeName”)有效(并且没有RefreshCache )。 有人可以解释原因吗? UPDATE3 如果我向项目提供FQDN,它可以工作: LDAP://srv00014.ssab.com/CN=SomeName,xxxx 赏金 我正在寻找解决以下问题的答案: 为什么entry.Properties[“customAttributeName”]因上述exception而失败 […]

如何获取UserPrincipal类未表示的Active Directory属性

我的意思是,现在我正在使用System.DirectoryServices.AccountManagement,如果我使用UserPrincipal类,我只看到名称,中间名等 所以在我的代码中它就像 UserPrincipal myUser = new UserPrincipal(pc); myUser.Name = “aaaaaa”; myUser.SamAccountName = “aaaaaaa”; . . . . myUser.Save(); 我怎样才能看到像移动或信息这样的属性?

Active Directory服务:PrincipalContext – “容器”对象的DN是什么?

我目前正在尝试使用PrincipalContext类通过Active Directory服务进行身份validation。 我想让我的应用程序使用密封和SSL上下文对域进行身份validation。 为了做到这一点,我必须使用PrincipalContext的以下构造函数(链接到MSDN页面) : public PrincipalContext( ContextType contextType, string name, string container, ContextOptions options ) 具体来说,我正在使用构造函数: PrincipalContext domainContext = new PrincipalContext( ContextType.Domain, domain, container, ContextOptions.Sealing | ContextOptions.SecureSocketLayer); MSDN说“容器”: 商店中的容器用作上下文的根。 所有查询都在此根下执行,并且所有插入都将在此容器中执行。 对于Domain和ApplicationDirectory上下文类型,此参数是容器对象的可分辨名称(DN)。 容器对象的DN是多少? 如何找出容器对象是什么? 我可以查询Active Directory(或LDAP)服务器吗?

使用DirectorySearcher.FindAll()时内存泄漏

我有一个漫长的运行过程,需要经常在Active Directory上进行大量查询。 为此,我一直使用System.DirectoryServices命名空间,使用DirectorySearcher和DirectoryEntry类。 我注意到应用程序中存在内存泄漏。 它可以使用以下代码重现: while (true) { using (var de = new DirectoryEntry(“LDAP://hostname”, “user”, “pass”)) { using (var mySearcher = new DirectorySearcher(de)) { mySearcher.Filter = “(objectClass=domain)”; using (SearchResultCollection src = mySearcher.FindAll()) { } } } } 这些类的文档说如果没有调用Dispose(),它们将泄漏内存。 我试过没有处理过,它只是泄漏了更多的内存。 我已经使用框架版本2.0和4.0对此进行了测试。之前是否有人遇到此问题? 有没有解决方法? 更新:我尝试在另一个AppDomain中运行代码,它似乎也没有帮助。

使用DirectoryServices从C#连接到LDAP

我正在尝试连接到运行LDAP的edirectory 8.8服务器。 我将如何在.Net中进行此操作? 我是否仍然可以使用System.DirectoryService中的类,例如DirectoryEntry和DirectorySearcher,或者它们是否特定于AD? 我是否需要以不同方式指定“连接字符串”? 我正在尝试类似下面的代码,但它似乎不起作用…… DirectoryEntry de = new DirectoryEntry (“LDAP://novellBox.sample.com”,”admin”,”password”,AuthenticationTypes.None); DirectorySearcher ds = new DirectorySearcher(de); var test = ds.FindAll(); 有任何想法吗?

如何通过LDAP + SSLvalidationActive Directory信誉?

我正在尝试使用.NET 3.5 System.DirectoryServices.AccountManagement命名空间来validation通过SSL加密LDAP连接对我们的Active Directory LDAP服务器的用户凭据。 这是示例代码: using (var pc = new PrincipalContext(ContextType.Domain, “sd.example.com:389”, “DC=sd,DC=example,DC=com”, ContextOptions.Negotiate)) { return pc.ValidateCredentials(_username, _password); } 此代码在不安全的LDAP(端口389)上工作正常,但我宁愿不以明文forms传输用户/传递组合。 但是,当我更改为LDAP + SSL(端口636)时,我得到以下exception: System.DirectoryServices.Protocols.DirectoryOperationException: The server cannot handle directory requests. at System.DirectoryServices.Protocols.ErrorChecking.CheckAndSetLdapError(Int32 error) at System.DirectoryServices.Protocols.LdapSessionOptions.FastConcurrentBind() at System.DirectoryServices.AccountManagement.CredentialValidator.BindLdap(NetworkCredential creds, ContextOptions contextOptions) at System.DirectoryServices.AccountManagement.CredentialValidator.Validate(String userName, String password) at System.DirectoryServices.AccountManagement.PrincipalContext.ValidateCredentials(String userName, String password) at (my code) 端口636适用于其他活动,例如查找该LDAP […]