C# 从当前登录用户的Active Directory中获取可分辨名称
如何从Active Directory中获取C#中当前登录用户的可分辨名称 检查以下代码段。您必须从中转到C# 从当前登录用户的Active Directory中获取可分辨名称,c#,.net,active-directory,distinguishedname,C#,.net,Active Directory,Distinguishedname,如何从Active Directory中获取C#中当前登录用户的可分辨名称 检查以下代码段。您必须从中转到Identity.Name。我假设用户已经在Active Directory中进行了身份验证(即使用标准IIS授权方法) 检查以下代码段。您必须从中转到Identity.Name。我假设用户已经在Active Directory中进行了身份验证(即使用标准IIS授权方法) 你为什么不直接使用:System.DirectoryServices.AccountManagement.UserPri
Identity.Name
。我假设用户已经在Active Directory中进行了身份验证(即使用标准IIS授权方法)
检查以下代码段。您必须从中转到
Identity.Name
。我假设用户已经在Active Directory中进行了身份验证(即使用标准IIS授权方法)
你为什么不直接使用:
System.DirectoryServices.AccountManagement.UserPrincipal.Current.differentiedName
你为什么不直接使用:System.DirectoryServices.AccountManagement.UserPrincipal.Current.differentiedName
LDAP你指的是Active Directory?是的,我是说对不起!Sp请将您的问题从LDAP更改为AD,谢谢。可能的重复。标题不同,但本质上是同一个问题。LDAP是指Active Directory?是的,我是指广告-对不起!Sp请将您的问题从LDAP更改为AD,谢谢。可能的重复。标题不同,但本质上是同一个问题。我正在与DirectoryEntry进行斗争,我无法使用System.DirectoryServices.DirectoryEntry,因为它不存在。有关于这个问题的提示吗?我如何导入它?它在System.DirectoryServicesWell中,这就是问题所在。我没有它的条目,请参阅:您必须在项目中将引用添加到System.DirectoryServices-右键单击项目并选择添加引用。啊,就是这样。谢谢。:)我是一名Java程序员,从来没有用过C语言。这就是为什么我会问一些愚蠢的问题。我正在与DirectoryEntry进行斗争,我无法使用System.DirectoryServices.DirectoryEntry,因为它不存在。有关于这个问题的提示吗?我如何导入它?它在System.DirectoryServicesWell中,这就是问题所在。我没有它的条目,请参阅:您必须在项目中将引用添加到System.DirectoryServices-右键单击项目并选择添加引用。啊,就是这样。谢谢。:)我是一名Java程序员,从来没有用过C语言。这就是为什么我要问愚蠢的问题。对不起,我不知道MSA是什么。它是管理服务帐户,如域\用户$。对不起,我不知道MSA是什么。它是管理服务帐户,如域\用户$
private string GetUserName(string identity)
{
if (identity.Contains("\\"))
{
string[] identityList = identity.Split('\\');
return identityList[1];
}
else
{
return identity;
}
}
public string GetUserDn(string identity)
{
var userName = GetUserName(identity);
using (var rootEntry = new DirectoryEntry("LDAP://" + adConfiguration.ServerAddress, null, null, AuthenticationTypes.Secure))
{
using (var directorySearcher = new DirectorySearcher(rootEntry, String.Format("(sAMAccountName={0})", userName)))
{
var searchResult = directorySearcher.FindOne();
if (searchResult != null)
{
using (var userEntry = searchResult.GetDirectoryEntry())
{
return (string)userEntry.Properties["distinguishedName"].Value;
}
}
}
}
return null;
}