Tag: ldap

转换方法以使用异步

我正在转换身份validation过程以支持异步,VS 2015 IDE警告我以下消息: async方法缺少’await’运算符并将同步运行…等… 无论如何,代码连接到LDAP商店并validation用户的帐户等…我已经尝试了各种各样的东西等待,但我只是在这里遗漏了一些东西。 我把代码恢复到以前的状态..我将非常感谢能够正确支持异步的任何指导… 这是代码: public async Task GetAsyncADUser(PrincipalContextParameter param) { try { if (UseLDAPForIdentityServer3) { using (var pc = new PrincipalContext(ContextType.Domain, param.ADDomain, param.ADServerContainer, param.ADServerUser, param.ADServerUserPwd)) { UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(pc, param.UserNameToValidate); if (userPrincipal != null) { bool isvalid = pc.ValidateCredentials(userPrincipal.DistinguishedName, param.UserPasswordToValidate, ContextOptions.SimpleBind); if (isvalid) { User user = new User { ad_guid […]

限制LDAP查询中返回的属性

如何通过System.DirectoryServices限制LDAP查询中返回的属性? 我一直在使用DirectorySearcher并将我想要的属性添加到DirectorySearcher.PropertiesToLoad。 问题是,这只是确保添加的属性包含在DirectoryEntry.Properties以及一些默认列表中。 有没有办法指定您想要返回的唯一属性? DirectoryEntry base = new DiectoryEntry(rootPath, null, null, AuthenticationTypes.FastBind); DirectorySearcher groupSearcher = new DirectorySearcher(base); groupSearcher.Filter = “(objectClass=group)”; groupSearcher.PropertiesToLoad.Add(“distinguishedName”); groupSearcher.PropertiesToLoad.Add(“description”); foreach (SearchResult groupSr in groupDs.FindAll()) … 在foreach循环中,当我获得组DirectoryEntry时,我可以访问大约16种不同的属性,而不仅仅是我指定的两个属性(distinguishedName,description)

服务位置协议的客户端实现示例?

有谁知道可以在Windows机器上构建/运行的服务定位协议的一个很好的示例实现?

分页LDap搜索失败,并显示“请求的属性不存在”

我需要使用使用.NET / C#实现的Ldap搜索来获得所有“epersonstatus = REMOVE”员工的’employeenumber’: var connection = new LdapConnection(“foo.bar.com:389”); connection.AuthType = AuthType.Anonymous; connection.SessionOptions.ProtocolVersion = 3; connection.Bind(); var request = new SearchRequest( “dc=root,dc=com”, “(epersonstatus=REMOVE)”, SearchScope.Subtree, new string[] { “employeenumber” }); 由于我有数以千计的条目,我使用此处提出的分页请求: http : //dunnry.com/blog/PagingInSystemDirectoryServicesProtocols.aspx 我还检查了服务器是否支持此处提出的分页请求: iPlanet LDAP和C#PageResultRequestControl 一旦流量到达: SearchResponse response = connection.SendRequest(request) as SearchResponse; 我得到一个DirectoryOperationException,消息“请求的属性不存在”。 通过在像softerra这样的LDap客户端上运行相同的查询,我得到条目(一千)和错误。 一些帮助将不胜感激。

递归查询LDAP组成员资格

我正在编写一个基于MVC(.NET 4.0)的网站,该网站需要我公司LDAP服务器的登录凭据。 我的代码需要的是仅允许属于某个组的用户。 例如,我可能正在寻找属于“企业IT”小组的用户。 我的凭据可能是“系统管理员”组的一部分,该组是“企业IT”的子组。 我正在使用表单身份validation。 如何以递归方式检查用户登录时所在的组?

什么是LDAP的连接字符串?

在这里我需要如何使用它: string tmpDirectory = String.Format(“LDAP://ou={0},dc={1},dc={2}”, parentOrganizationUnit, domainName, domainExtension ); 当我尝试使用此连接运行一些代码时,我得到一个例外。 ( 有关更多信息,请参阅此问题 )。 我被告知我需要提供连接字符串凭证 – 用户名和密码。 什么是连接字符串? 我需要确切的语法。 :) 谢谢! 我正在使用Windows Server 2003和Active Directory。

如何在C#中从LDAP读取TermainsServices IADsTSUserEx属性?

我从AD中读过以下属性, TerminalServicesProfilePath TerminalServicesHomeDirectory TerminalServicesHomeDrive 我已经尝试过DirectoryEntry和DirectorySearcher。 但他们不包括这些属性。 我在vbscript和VC中找到了一些例子来读取它们。 但是我没能在C#中工作。 我错过了一些棘手的事情吗? 编辑:我必须在“Windows Server”上运行它才能使其正常工作吗? 可以从win XP中读取吗?

.NET LDAP路径实用程序(C#)

是否有用于LDAP路径操作的.NET库? 我想有一些等同于System.IO.Path东西,允许例如做类似的东西 string ou1 = LDAPPath.Combine(“OU=users”,”DC=x,DC=y”); string ou2 = LDAPPath.Parent(“CN=someone,OU=users,DC=x,DC=y”); 否则,在.NET中处理LDAP专有名称的常用方法是什么? 澄清我的问题 :我一般不会问“.NET中的目录服务”; 我已经使用过它并完成了一些程序来执行某些任务。 我觉得缺少的是一种操纵路径 ,解析专有名称等的正确方法,因为这应该是一个非常常见的需求,我希望有一种更简洁的方法来做到这一点,而不是在逗号上分割字符串(1)。 (1)例如,像在库中调用一个函数来分割逗号上的字符串

DirectorySearcher FindOne()在初始执行时延迟

我在执行DirectorySearcher FindOne()和我看到的第一个网络数据包之间的初始延迟时间为2-5秒。 初始执​​行后,后续执行立即完成约45秒。 在快速执行的那段时间之后,下一次执行将被延迟,并且所有后续执行将立即完成。 似乎有某种缓存正在进行,但我无法找到任何确认或描述导致初始延迟的资源。 我们在客户端Windows 2008服务器上注意到了这一点,然后在我们自己的Windows 2008和Windows 7盒子上重现。 这是我简单的.NET 4.0 C#应用程序的样子。 延迟发生在“已启动”和“已完成”消息之间。 知道为什么这个延迟发生在最初的FindOne()执行上? 任何帮助深表感谢! using System; using System.Collections.Generic; using System.Text; using System.DirectoryServices; namespace LdapTest { class Program { static void Main(string[] args) { string[] fetchAttributes; fetchAttributes = new string[] { “{string[0]}” }; using (DirectoryEntry searchRoot = new DirectoryEntry(“LDAP://localserver/ou=lab,dc=ourdomain,dc=com”, “cn=binduser,ou=Services,dc=ourdomain,dc=com”, “Password”, AuthenticationTypes.ReadonlyServer)) { using (DirectorySearcher […]

如何使用C#更好地查询Active Directory中的多个域?

我正在尝试将LDAP / AD搜索从仅在当前登录的域中搜索扩展到搜索AD中的所有域。 该方法接受带有查询的字符串,并返回并返回LDAPInformation对象。 虽然我在问,有没有更好的方法来搜索名称而不是这种方式? 如果用姓氏寻找一个人需要使用通配符,这是用户不友好的(例如:Doe *)。 public static LDAPInformation[] GetGlobalAddressListVIAName(string nameQuery) { var currentForest = Forest.GetCurrentForest(); var globalCatalog = currentForest.FindGlobalCatalog(); using (var searcher = globalCatalog.GetDirectorySearcher()) { using (var entry = new DirectoryEntry(searcher.SearchRoot.Path)) { searcher.Filter = “(&(mailnickname=*)(objectClass=user)(displayName=” + nameQuery + “))”; searcher.PropertyNamesOnly = true; searcher.SearchScope = SearchScope.Subtree; searcher.Sort.Direction = SortDirection.Ascending; searcher.Sort.PropertyName = “displayName”; return searcher.FindAll().Cast().Select(result […]