Tag: ldap

UserPrincipal.FindByIdentity()始终返回null

我正在使用LdapAuthentication将用户登录到Active Directory。 我想找到用户所属的所有组。 我使用以下代码: string adPath = “LDAP://OU=HR Controlled Users,OU=All Users,DC=myDomain,DC=local”; LdapAuthentication adAuth = new LdapAuthentication(adPath); try { if (true == adAuth.IsAuthenticated(“myDomain”, txtLoginEmail.Text, txtLoginPassword.Text)) { string email = txtLoginEmail.Text; using (PrincipalContext context = new PrincipalContext(ContextType.Domain)) { UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.Name, email); foreach (var group in user.GetGroups()) { Console.WriteLine(group.Name); } } } } catch(Exception e) […]

PermissiveModifyControl在C#LDAP中抛出DirectoryOperationException

使用System.DirectoryServices.Protocols命名空间在Active Directory组上添加/修改属性。 码: public void UpdateProperties(Dictionary Properties) { List directoryAttributeModifications; // … Code to convert Properties dictionary to directoryAttributeModifications // There is one ‘Add’ modification, to set the ‘description’ of the group ModifyRequest modifyRequest = new ModifyRequest(groupDistinguishedName, directoryAttributeModifications.ToArray()); modifyRequest.Controls.Add(new PermissiveModifyControl()); ModifyResponse response = connection.SendRequest(modifyRequest) as ModifyResponse; PermissiveModifyControl旨在防止代码在描述已存在时失败。 我发现PermissiveModifyControl的唯一信息在这里: http : //msdn.microsoft.com/en-us/library/bb332056.aspx 其中说明: 如果LDAP修改请求尝试添加已存在的属性或尝试删除不存在的属性,则它通常会失败。 使用PermissiveModifyControl ,修改操作成功,而不会抛出DirectoryOperationException错误。 […]

.Net代码将Active Directory属性设置为“未设置”

在Active Direcotry mmc管理单元中,您无法看到“未设置”的属性。 使用ADSIEDIT.MSC工具时,如果属性值为null,则会将其视为“未设置”。 如何在.Net代码中将属性设置为“未设置”? 以下是Powershell中的答案,但我需要使用一些.Net代码(VB.Net/C#)。 http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/d6d0bfa1-73da-41ea-a7f5-f622de9f7d1b/ ps msExchHideAddressLists是罪魁祸首属性,当此域中的True或False时,它会阻止用户信息从AD复制到Sharepoint。

如何查询一个域的用户是否是另一个AD域中的组的成员?

我有一系列应用程序都使用我创建的相同C#,。Net 2.0代码来检查并查看用户是否是Active Directory组的成员。 直到最近,当我将另一个受信任的AD域中的用户添加到我的一个AD组时,我的代码没有遇到任何问题。 我的问题是如何检查用户是否是Active Directory组的成员,无论他们的域名是谁。 换句话说,它们可能与我的组在同一个域中,也可能不在同一个域中。 下面是我编写并使用多年来搜索以查看用户是否在Active Directory组中的代码。 我不确定我在哪里修改了这段代码,但我认为它来自MSDN文章。 此外,解决方案必须是.Net 2.0框架。 我找到了很多可能适用于.Net 3.5中此问题的答案。 不幸的是,这对我的方案不起作用。 //This method takes a user name and the name of an AD Group (role). //Current implementations of this method do not contain the user’s domain //with userName, because it comes from the Environment.UserName property. private static bool IsInRole(string userName, string […]

如果用户帐户处于活动状态,如何签入C#

如何从C#中检查本地用户帐户(即本地管理员帐户)是否处于活动状态? 我真正想要的是“网络用户管理员”命令的“帐户活动”=“是”(或“否”)输出的C#替换。 我担心这个问题看起来像这个问题的副本,但我不知道要为根DirectoryEntry对象的参数传递什么。 尝试了不同的东西,如“ldap://”+ Environment.MachineName,“ldap://127.0.0.1”,“WinNT://”+ Environment.MachineName,但都没有奏效。 在所有三种情况下,我都会通过searcher.FindAll()调用抛出exception。

在.Net 4.0中,DirectorySearch能否以允许我翻阅它们的方式返回LDAP结果?

我正在使用C#,并且正在尝试使用DirectorySearch查询极大的Microsoft ActiveDirectory LDAP服务器的组。 因此,在我的应用程序中,我将有一个具有搜索function的分组列表。 当然,每次点击“下一页”时,我都不想通过向我传递这些查询的整个结果集来敲击我的LDAP服务器。 有没有办法,使用DirectorySearch,只检索单个任意页面的结果,而不是在一个方法调用中返回整个结果集? 类似的问题: DirectorySearch.PageSize = 2不起作用 c #Active Directory服务findAll()仅返回1000个条目 存在许多这样的问题,其中有人询问分页(意味着从LDAP服务器到应用服务器),并获得涉及PageSize和SizeLimit的响应。 但是,这些属性仅影响C#服务器和LDAP服务器之间的分页,最后,DirectorySearch唯一相关的方法是FindOne()和FindAll()。 我正在寻找的基本上是“FindPaged(pageSize,pageNumber)”(pageNumber是非常重要的一点。我不只是想要前1000个结果,我想要(例如)第100集1000个结果。应用程序不能等待100,000条记录从LDAP服务器传递到应用服务器,即使它们被分解为1,000条记录块。 我知道DirectoryServices.Protocols有SearchRequest,它(我认为?)允许你使用“PageResultRequestControl”,它看起来像我正在寻找的东西(虽然它看起来像分页信息来自“cookies”,我不确定我应该如何检索)。 但是,如果有一种方法可以做到这一点,而不是重写整个事物而不是使用协议,我宁愿不必这样做。 我无法想象没有办法做到这一点……甚至SQL都有Row_Number。 更新:PageResultRequestControl没有帮助 – 它只是向前和顺序(您必须调用并获得前N个结果,然后才能获得调用获得结果N + 1所需的“cookie”标记)。 但是,cookie看起来确实有某种可重复的排序……在我正在研究的结果集上,我逐个遍历结果,每次cookie都出现了: 1: {8, 0, 0, 0} 2: {11, 0, 0, 0} 3: {12, 0, 0, 0} 4: {16, 0, 0, 0} 当我迭代两次,我得到相同的数字(11,16)。 这让我觉得,如果我能弄清楚这些数字是如何生成的代码,我可以创建一个ad-hoc cookie,这将给我一个我正在寻找的分页。

LDAP服务器不可用

我是个新手 尝试使用PrincipalContext连接到ldap服务器。 我试过这个网站上的所有解决方案都无济于事。 我尝试过的事情: PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Domain); PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Domain, “ldap://localhost:389/dc=maxcrc,dc=com”); PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Domain, “maxcrc.com”); 所有都给出了相同的结果: LDAP服务器不可用 只有ContextType.Machine基本上ContextType.Machine工作。 不确定我的LDAP服务器是否设置正确: 主持人:localhost 港口:389 基本DN:dc = maxcrc,dc = com URL:ldap:// localhost:389 / dc = maxcrc,dc = com 使用Softerra LDAP浏览器进行测试 从头到尾的任何教程都将非常感谢…

Ldap查询特定于组的所有成员

我希望获得属于特定组’groupName’的用户列表传递给私有方法。 DirectoryEntry de = new DirectoryEntry(“LDAP://DC=xxxx,DC=net”); // Root Directory // var ds = new DirectorySearcher(de); ds.PropertiesToLoad.Add(“SAMAccountName”); ds.PropertiesToLoad.Add(“member”); ds.Filter = “(&(objectClass=group)(SAMAccountName=” + groupName + “))”; SearchResultCollection AllGroupUsers; AllGroupUsers = ds.FindAll(); 该查询返回3个属性: – adspath,accountName和member。 成员是我真正追求的。我访问成员属性及其值,如下面的代码所示: – if (AllGroupUsers.Count > 0) { ResultPropertyValueCollection values = AllGroupUsers[0].Properties[“member”]; 但这里发生了一些奇怪的事 在等号的RHS上,AllGroupUsers具有特定成员的值“CN = Mike Schoomaker R,……..” 在等号的LHS上,值为“CN = Mike Schoomaker(OR),…..” 我不太确定这是怎么可能的…… AllGroupUsers下的每一个值都不会发生…只有我知道的事情才会发生在活动目录上的外部用户…有谁能告诉我我是怎么做的可以修复此问题并获取实际的firstName,LastName和MiddleInitial?

:通过IdentityServer3通过LDAPvalidation用户

我需要一种方法来通过IdentityServer3validation组织内的用户(使用LDAP和Active Directory)并授予他们对资源的访问权限。 IdentityServer3似乎是OpenID Connect协议的实现框架,适用于身份validation和授权。 到目前为止,我已经能够使用InMemory实现validation硬编码用户并获得JWT(JSON Web令牌)访问令牌。 请参考这个例子: https://rajdeep.io/2015/05/07/creating-a-single-sign-on-using-thinktecture-identity-server-part-1/ 但是,在我必须validation大型组织中的用户(存储在活动目录中)并发出令牌来访问资源的情况下,这不会非常有用。 以下是我根据此链接所做的工作 ( http://stackoverflow.com/questions/31536420/thinktecture-identityserver-v3-with-windowsauth ): 创建了一个实现IUserService的ActiveDirectoryUserService。 namespace LDAPSSO { public class ActiveDirectoryUserService : IUserService { private const string DOMAIN = “company domain”; public Task AuthenticateExternalAsync(ExternalIdentity externalUser, SignInMessage message) { return Task.FromResult(null); } public Task AuthenticateLocalAsync(string username, string password, SignInMessage message) { try { using (var pc = […]

从adlds实例validationasp.net mvc 5应用程序

您好我想集成LDAP(安装在Windows 8.1机器上的AD LDS)表格validation到我的mvc 5应用程序。 我不知道我是否遗漏了web.config上的内容或我的c#代码错误但我已成功连接ldp.exe和ADSI编辑为User = Admin,其管理员权限如此处所示 在我的网络配置中我添加了这些行: 我的登录方法请注意我正在传递(txtDomainName = App.com,txtUserName = Admin,txtPassword = Azerty * 123): [AllowAnonymous] [HttpGet] public ActionResult Login () { return View(); } [AllowAnonymous] [HttpPost] public ActionResult Login(string txtDomainName, string txtUserName, string txtPassword) { // Path to you LDAP directory server. // Contact your network administrator to obtain a valid path. […]