Tag: active directory

在全局编录中validation用户

我需要在给定userId,域和密码的情况下validation用户的Windows凭据。 我们的Active Directory包含多个域,其中一些我们可以使用以下代码列出: var domains = System.DirectoryServices.ActiveDirectory.Forest.GetCurrentForest().Domains; 但是,我们还拥有属于林外域的用户。 但是,我可以从全球目录(GC)访问它们。 下面的代码允许我获取userid的目录条目。 System.DirectoryServices.DirectoryEntry globalCatalogDE = new System.DirectoryServices.DirectoryEntry(“GC://DC=nsroot,DC=net”); var ds = new System.DirectoryServices.DirectorySearcher(globalCatalogDE); ds.Filter = “(&(objectClass=user)(sAMAccountName=” + userId + “))”; System.DirectoryServices.DirectoryEntry userDE = ds.FindAll()[0].GetDirectoryEntry(); 如何validation属于我无法直接访问但在GC中可用的域的用户?

如何使用System.DirectoryServices.ActiveDirectory.Domain类获取域别名

我们有一个全名域名,例如long-domainname.com ; 此域名将替换为别名short 。 可以使用netapi32.dll检索此别名,如下所示: [DllImport(“Netapi32.dll”)] static extern int NetApiBufferFree(IntPtr Buffer); // Returns the domain name the computer is joined to, or “” if not joined. public static string GetJoinedDomain() { int result = 0; string domain = null; IntPtr pDomain = IntPtr.Zero; NetJoinStatus status = NetJoinStatus.NetSetupUnknownStatus; try { result = NetGetJoinInformation(null, out pDomain, out […]

扩展GroupPrincipal和Members属性

我想扩展GroupPrincipal类来处理一些自定义属性: using System.DirectoryServices.AccountManagement; [DirectoryRdnPrefix(“CN”)] [DirectoryObjectClass(“group”)] public class MyGroupPrincipal : GroupPrincipal { // … } 我如何覆盖MyGroupPrincipal的Members属性,以便如果它有一个组成员,则返回MyGroupPrincipal而不是GroupPrincipal的实例? 我想写一下 MyGroupPrincipal group = GetGroup(); foreach (var m in group.Members) { if (m is MyGroupPrincipal) { // always fails: m is a normal GroupPrincipal // do something } }

C#Active Directory调用“ChangePassword”无法联系域

我们使用Active Directory类构建在ASP.NET C#上的自定义应用程序可以很好地更改Active Directory用户的密码,但是只要在服务器上安装了以下更新,它就会停止工作 https://support.microsoft.com/en-us/kb/3167679 https://support.microsoft.com/en-us/kb/3177108 现在我们的密码管理器应用程序无法更改密码。 我们卸载了更新的,它开始工作得很好。 我们得到了微软的支持,但是他们不愿意为此提供帮助,因为他们将此视为编码问题。 对我来说,似乎是早期工作的活动目录问题。 一旦我们调用changepassword函数,应用程序就会抛出以下exception: 系统无法联系域控制器来为身份validation请求提供服务。 请稍后再试。 (HRESULTexception:0x800704F1) userEntry.Invoke(“ChangePassword”,new object [] {currentPassword,newPassword}); //这一行给出了错误 我查看了互联网,似乎很多人/公司在MS更新后遇到了这个问题。 如果有其他方法可以在不卸载更新的情况下解决此问题,您能否告诉我? Microsoft是否计划发布不同的路径或安全更新来克服此情况? 任何帮助将受到高度赞赏。

如何获取域控制器IP地址

如何使用C#编程方式获取域控制器IP地址?

System.DirectoryServices.DirectoryServicesCOMException(0x800700EA):有更多数据可用

由于某种原因,在星期一,上周工作的代码突然开始给我以下错误。 System.DirectoryServices.DirectoryServicesCOMException(0x800700EA):有更多数据可用。 当我尝试针对广告查询执行FindAll时会发生这种情况 我做了一个小型控制台应用程序,并能够重现错误。 什么会导致此错误发生? static void Main(string[] args) { var propToLoad = new StringCollection(); propToLoad.Add(ADProperty.DistinguishedName); DirectoryEntry de = new DirectoryEntry(); de.Path = “MySearchROOT”; DirectorySearcher ser = new DirectorySearcher(de); ser.Filter = “(&(&(&(dfaitUserType=PER)(objectCategory=person)(objectClass=user)(!dfaitObjectStatus=*)(!msExchHideFromAddressLists=TRUE))(&(sAMAccountName=*)(dfaitOrgCode=*)(objectCategory=person)(objectClass=user)(!dfaitObjectStatus=*)(!msExchHideFromAddressLists=TRUE)))(|(employeeType=CBS)(employeeType=LES)(employeeType=CON)(employeeType=OGD)(employeeType=OTH)(employeeType=MIN)))”; // We made constants to represent all the Ad properties ser.PropertiesToLoad.Add(ADProperty.Surname); ser.PropertiesToLoad.Add(ADProperty.GivenName); ser.PropertiesToLoad.Add(ADProperty.Mail); ser.PropertiesToLoad.Add(ADProperty.DisplayName); ser.PropertiesToLoad.Add(ADProperty.DfaitEdsId); ser.PropertiesToLoad.Add(ADProperty.DistinguishedName); ser.PropertiesToLoad.Add(ADProperty.MemberOf); ser.PropertiesToLoad.Add(ADProperty.EmployeeType); ser.PropertiesToLoad.Add(ADProperty.Department); ser.PropertiesToLoad.Add(ADProperty.Company); ser.PropertiesToLoad.Add(ADProperty.MSExchHideFromAddressLists); ser.PropertiesToLoad.Add(ADProperty.MailNickname); ser.PropertiesToLoad.Add(ADProperty.Initials); […]

C#:如何在启用SSL的情况下连接到Active Directory?

我正在处理的项目将与客户A​​ctive Directory集成,以便对用户进行身份validation。 我一直在尝试编写一些可以检索用户密码的代码,我知道Active Directory只会通过端口636上的SSL连接公开相关属性。 以下代码以编程方式连接而不使用SSL,但后来我看不到密码属性: static void Main(string[] args) { DirectoryEntry entry = new DirectoryEntry(@”LDAP:///CN=LDAP Test,CN=Users,DC=customer,DC=com”); entry.AuthenticationType = AuthenticationTypes.None; entry.Username = “CN=LDAP Test,CN=Users,DC=customer,DC=com”; entry.Password = “”; if (entry != null) { foreach (Object propName in entry.Properties.PropertyNames) { Console.WriteLine((String)propName); } } } 当我更改代码以使用SSL时,我得到一个exception说明;未知错误(0x80005000)’。 我在托管Active Directory的服务器上启用了SSL,在同一台服务器上安装了Microsoft CA并从CA获得了证书。 我可以使用Apache Directory Studio通过SSL连接到Active Directory,但不显示密码属性。 以下代码显示了我一直尝试使用SSL进行连接的内容: static void Main(string[] args) { […]

在Active Directory中找不到Locked属性(C#)

首先,我知道有很多关于这个主题的post,但是我发现的所有信息对我的情况没有帮助。 发生的事情是我找不到属性在AD中锁定用户的位置。 我用过 链接文字 对于AD的所有其他内容,它已经全部工作了,如果帐户被锁定,userAccountControl的位图不会改变。 尝试访问lockoutTime会返回一个exception,说它无法找到该属性。 唯一远程工作的是 user.InvokeGet( “IsAccountLocked”) 呼叫,但无论帐户是否被锁定,它总是返回false。 如果有人有任何想法,那将是非常有帮助的,或者链接可能会帮助我。 谢谢

读取/过滤分发组的活动目录的子组?

我有一个域名为myDomain.local的Active Directory,在它下面存在一个包含许多组的通讯组。 如何(以编程方式)读取所有这些子组以检索其名称列表? 以及如何优化查询以过滤结果,以便它只检索以Region结尾的所有组? 顺便说一下,我正在使用C#.Net,ASP.Net和sharepoint,而且我没有AD经验。

在Active Directory中搜索与电子邮件地址关联的所有用户名

我有一种方法可以根据电子邮件地址在Active Directory中搜索用户名。 有些情况下,给定的电子邮件地址可能有多个用户名,我正在尝试捕获这些用户名。 我已经重写了我的方法,但似乎无法使语法完全正确。 我相信这个问题就是这个问题。 foreach (Object myObject in result.Properties[property]) 谢谢, 贾森 private String FindNameByEmail(string emailAddress) { DirectoryEntry entry = GetDirectoryEntry(); emailAddress = txtEmailID.Text; DirectorySearcher search = new DirectorySearcher(entry); search.Filter = “(&(objectCategory=person)(sAMAccountName=*)(mail=” + emailAddress + “))”; string[] properties = new string[] { “SAMAccountName” }; foreach (String property in properties) search.PropertiesToLoad.Add(property); SearchResultCollection result = search.FindAll(); if […]