有没有办法让用户在 ASP.Net Core 的活动目录中获得完整路径?
Is there a way to get users full path in active directory in ASP.Net Core?
我需要验证特定用户在活动目录中的路径,以便让他验证我的网站。有没有一种方法可以让用户获取完整路径。我已经研究过 PrincipalSearch,但我认为它不适用于特定用户,它会搜索完整的 AD。
这是我目前所拥有的:
PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, ip, container, user, pass);
UserPrincipal userAD = UserPrincipal.FindByIdentity(principalContext, username);
if (userAD != null)
{
if (principalContext.ValidateCredentials(username, password))
{
return true;
}
else
{
return false;
}
我想获取 userAD 变量中使用的用户在 Active Directory 中的完整路径。我应该怎么做?有什么建议吗?
我使用了 DistinguishedName 方法来获取用户的位置。代码现在是这样的:
PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, ip, container, user, pass);
UserPrincipal userAD = UserPrincipal.FindByIdentity(principalContext, username);
var path = userAD.DistinguishedName;
if (userAD != null)
{
if(path.Contains("blabla")){
if (principalContext.ValidateCredentials(username, password))
{
return true;
}
else
{
return false;
}
}
DistinguishedName returns userAD 中指定的用户的完整路径。希望这有用!
我需要验证特定用户在活动目录中的路径,以便让他验证我的网站。有没有一种方法可以让用户获取完整路径。我已经研究过 PrincipalSearch,但我认为它不适用于特定用户,它会搜索完整的 AD。 这是我目前所拥有的:
PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, ip, container, user, pass);
UserPrincipal userAD = UserPrincipal.FindByIdentity(principalContext, username);
if (userAD != null)
{
if (principalContext.ValidateCredentials(username, password))
{
return true;
}
else
{
return false;
}
我想获取 userAD 变量中使用的用户在 Active Directory 中的完整路径。我应该怎么做?有什么建议吗?
我使用了 DistinguishedName 方法来获取用户的位置。代码现在是这样的:
PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, ip, container, user, pass);
UserPrincipal userAD = UserPrincipal.FindByIdentity(principalContext, username);
var path = userAD.DistinguishedName;
if (userAD != null)
{
if(path.Contains("blabla")){
if (principalContext.ValidateCredentials(username, password))
{
return true;
}
else
{
return false;
}
}
DistinguishedName returns userAD 中指定的用户的完整路径。希望这有用!