Tag: active directory

LdapConnection与PrincipalContext

我有以下两种使用LDAP和LDAPSvalidation用户的实现,我想知道哪个更好/更正确。 对于记录,这两个都适用于SSL和非SSL连接。 我也很好奇,因为在Non-SSL PrincipalContext版本上使用Wireshark观看时,我仍然看到端口636上的流量。在四种组合中( Non-SSL LdapConnection , SSL LdapConnection , Non-SSL PrincipalContext , SSL PrincipalContext ),它是只有一个在389和636端口都有流量,而不只是一个或另一个。 可能是什么导致了这个? LDAP连接方法: bool userAuthenticated = false; var domainName = DomainName; if (useSSL) { domainName = domainName + “:636”; } try { using (var ldap = new LdapConnection(domainName)) { var networkCredential = new NetworkCredential(username, password, domainName); ldap.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback((con, […]

ASP.NET Core通过web.config授权AD组

在我的旧.NET MVC应用程序中,我可以在IIS中启用Windows身份validation并禁用匿名。 然后在我的web.config文件中,我只需要输入: 在.NET Core 2.0中,这将无法正常工作 – 它会正确拒绝匿名,但无论如何都会授权所有用户。 如果我这样做: [Authorize(Roles = “Domain\\MyADGroupToHaveAccess”)] 在我的HomeController ,它可以工作,但我不想在我的项目中对此设置进行硬编码,因为它需要针对其他环境进行更改。 如何使web.config与AD授权一起使用? 或者是否有另一种方法可以在ASP.NET Core中不对此设置进行硬编码?

如何在复杂环境中使用FQDN获取NETBIOS域名

从完全限定的Active Directory域名获取NETBIOS域名有时是一项繁琐的工作。 我在这里找到了一个好的答案。 在具有多个林的环境中,如果PC不在您正在查询的林中,则此方法将不起作用。 这是因为LDAP://RootDSE将查询计算机域的信息。 有人可能会问:为什么这么复杂? 只需在检索到的第一个点之前使用该名称: ActiveDirectory.Domain.GetComputerDomain().Name; 或者只是获取用户的域名: Environment.GetEnvironmentVariable(“USERDOMAIN”); 要么 Environment.UserDomainName; 但是NETBIOS域名可能完全不同,您或您的计算机可能位于不同的域或林中! 所以这种方法只能在简单的环境中使用。 DJ KRAZE的解决方案只需要一个小的修改就可以进行跨域查询。 这假设了一种信任关系! private string GetNetbiosDomainName(string dnsDomainName) { string netbiosDomainName = string.Empty; DirectoryEntry rootDSE = new DirectoryEntry(string.Format(“LDAP://{0}/RootDSE”,dnsDomainName)); string configurationNamingContext = rootDSE.Properties[“configurationNamingContext”][0].ToString(); DirectoryEntry searchRoot = new DirectoryEntry(“LDAP://cn=Partitions,” + configurationNamingContext); DirectorySearcher searcher = new DirectorySearcher(searchRoot); searcher.SearchScope = SearchScope.OneLevel; searcher.PropertiesToLoad.Add(“netbiosname”); searcher.Filter = string.Format(“(&(objectcategory=Crossref)(dnsRoot={0})(netBIOSName=*))”, dnsDomainName); […]

如何在C#Web应用程序中找到用户的Active Directory显示名称?

我正在编写一个使用Windows身份validation的Web应用程序,我很乐意使用以下内容获取用户的登录名: string login = User.Identity.Name.ToString(); 但我不需要他们的登录名我想要他们的DisplayName。 我现在已经敲了几个小时…… 我可以通过Web应用程序访问我组织的AD吗?

如何从C#中的显示名称获取Active Directory中的用户名?

我希望能够使用该用户的显示名称获取Active Directory中用户的用户标识。 显示名称是从数据库中获取的,并且在该用户会话期间使用以下代码存储以获取显示名称: using System.DirectoryServices.AccountManagement; private string GetDisplayName() { // set up domain context PrincipalContext ctx = new PrincipalContext(ContextType.Domain); // find currently logged in user UserPrincipal user = UserPrincipal.Current; return user.DisplayName; } 这一次,我想有一个名为GetUserIdFromDisplayName()的方法,它返回Active Directory登录名。 有任何想法吗?

在.NET中创建Active Directory用户(C#)

我需要在Active Directory中创建一个新用户。 我找到了几个例子如下: using System; using System.DirectoryServices; namespace test { class Program { static void Main(string[] args) { try { string path = “LDAP://OU=x,DC=y,DC=com”; string username = “johndoe”; using (DirectoryEntry ou = new DirectoryEntry(path)) { DirectoryEntry user = ou.Children.Add(“CN=” + username, “user”); user.Properties[“sAMAccountName”].Add(username); ou.CommitChanges(); } } catch (Exception exc) { Console.WriteLine(exc.Message); } } } } […]

如何在Nancy中针对Active Directory进行身份validation?

这是一篇过时的文章,但http://msdn.microsoft.com/en-us/library/ff650308.aspx#paght000026_step3说明了我想做的事情。 我选择南希作为我的网络框架,因为它的简单性和低礼仪方法。 因此,我需要一种使用Nancy对Active Directory进行身份validation的方法。 在ASP.NET中,看起来您只需通过web.config文件中的某些设置在基于数据库的成员资格提供程序和Active Directory之间切换即可。 我不需要具体,但在开发和生产之间切换的能力将是惊人的。 如何才能做到这一点?

PrincipalSearcher和DirectorySearcher之间的区别

我看到使用PrincipalSearcher Active Directory示例以及执行相同操作但使用DirectorySearcher其他示例。 这两个例子有什么区别? 使用PrincipalSearcher示例 PrincipalContext context = new PrincipalContext(ContextType.Domain); PrincipalSearcher search = new PrincipalSearcher(new UserPrincipal(context)); foreach( UserPrincipal user in search.FindAll() ) { if( null != user ) Console.WriteLine(user.DistinguishedName); } 使用DirectorySearcher示例 DirectorySearcher search = new DirectorySearcher(“(&(objectClass=user)(objectCategory=person))”); search.PageSize = 1000; foreach( SearchResult result in search.FindAll() ) { DirectoryEntry user = result.GetDirectoryEntry(); if( null != user ) […]

使用C#中的密码创建Active Directory用户

我正在寻找一种方法来创建Active Directory用户并设置他们的密码,最好不要给我的应用程序/服务域管理员权限。 我尝试过以下方法: DirectoryEntry newUser = _directoryEntry.Children.Add(“CN=” + fullname, USER); newUser.Properties[“samAccountName”].Value = username; newUser.Properties[“userPassword”].Value = password; newUser.Properties[“mail”].Value = email; newUser.CommitChanges(); 用户已创建,但似乎从未在用户上设置密码。 有没有人知道如何在创建用户时最初设置用户密码? 我知道 .Invoke(“SetPassword”, new object[] { password }) 但这需要我的代码以域管理员权限运行。 因为我没有真正看到授予我的代码域管理员权限的重点,只是设置初始密码(我也允许用户密码重置,但那些在特定用户的上下文中运行),我希望有人聪明解决方案,不要求我这样做。 提前致谢!

Active Directory:调整函数的性能以检索组成员

这篇文章是对以下内容的跟进: Active Directory:DirectoryEntry成员列表 GroupPrincipal.GetMembers() 我有一个函数,它检索Active Directory中组的所有成员的distinguishedName属性。 此函数用于检索所有用户和组对象的大型脚本(总运行时间为7-10分钟)。 我的问题是distinguishedName上的下游SSIS查找非常慢。 这并不奇怪,因为它正在查找varchar(255)与UniqueIdentifier(16字节)。 我可以在源代码上执行SQL Select,然后使用Merge Join,这会加快速度。 但是,我注意到提取中存在潜在竞争条件(参见上面的运行时间),其中组成员存在而没有匹配的distinguishedName。 如果是这种情况,那么我需要解决这个问题; 但是,合并连接不会使加载失败,而查找可以设置为使加载失败。 所以,我需要通过distinguishedName动态获取guid。 但是,当我尝试使用下面的方法时,GetGroupMemberList函数的性能大幅下降。 是否有更好/更快的方式通过distinguishedName获取组成员guid? 方法(两个循环): listGroupMemberGuid.Add(new DirectoryEntry(“LDAP://” + member, null, null, AuthenticationTypes.Secure).Guid); listGroupMemberGuid.Add(new DirectoryEntry(“LDAP://” + user, null, null, AuthenticationTypes.Secure).Guid); function: private List GetGroupMemberList(string strPropertyValue, string strActiveDirectoryHost, int intActiveDirectoryPageSize) { // Variable declaration(s). List listGroupMemberDn = new List(); string strPath = strActiveDirectoryHost […]