我正在使用 DirectoryServices 针对 ADLDS(轻量级 Active Directory)对用户进行身份验证。我通过认证后。如何确定当前登录用户的 DN 或 SID?
using (DirectoryEntry entry = new DirectoryEntry(<a>LDAP://XYZ:389</a>,
userName.ToString(),
password.ToString(),
AuthenticationTypes.Secure))
{
try
{
// Bind to the native object to force authentication to happen
Object native = entry.NativeObject;
MessageBox.Show("User authenticated!");
}
catch (Exception ex)
{
throw new Exception("User not authenticated: " + ex.Message);
}
...
谢谢
更新:
我在
src = search.FindAll()
There is no such object on the server.
我意识到登录的用户在 Active Directory 轻量级中有一个类类型“foreignSecurityPrincipal”,所以我想也许我可以将您的过滤器修改为:
search.Filter = "(&(objectclass=foreignSecurityPrincipal)" + "(sAMAccountName=" + userName + "))";
但这给了我同样的例外。知道我缺少什么吗?