JD.*_*JD. 8 c# active-directory
我有一些代码使用PrincipalContext对象,并将特定的用户名和密码传递给其构造函数以绑定到Active Directory.
然后进行调用.ValidateCredentials()为正在验证的用户传递不同的用户名和密码.
我的问题是,为了让第一个用户在Active Directory中绑定,Active Directory中需要哪些权限?
当我开始研究这个主题时,我发现一切都非常令人困惑,本教程是最好的入门教程之一,因为有很多首字母缩略词,这增加了难度。 https://hynek.me/articles/ldap-a-gentle-introduction/
我会向您提及有关验证的类似问题,但不是专门针对凭据的问题,因为有几个与此类工作相关的代码片段。
我认为您要问的是身份验证功能
我认为发布我的整个代码只会让您感到困惑,因此我将解释它的结构,并希望能让您继续前进并给出一个片段。
我这样做的方式有很多,方法如下:
具有 IsAuthenticated 方法的公共类 LdapAuthentication,其中该方法传递域、用户名和密码
然后我使用 DirectoryEntry DirectorySearcher 查找并过滤 SAMAccountName 然后这取决于您的应用程序以及您要查找的内容。
但其中大部分都在 System.DirectoryServices 内部
try
{ //Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
return false;
}
//Update the new path to the user in the directory.
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}
Run Code Online (Sandbox Code Playgroud)
这应该足以让您开始搜索并获得您需要的内容。祝你好运!
| 归档时间: |
|
| 查看次数: |
1292 次 |
| 最近记录: |