【发布时间】:2011-05-20 22:44:27
【问题描述】:
我有一个代码,用于检查用户是否是 AD 的成员,运行良好,
现在我想添加检查用户是否也是组成员的可能性!
我需要修改什么来实现这一点,我做了一些工作,但它失败了!
这是我的代码:
//Authenticate a User Against the Directory
private bool Authenticate(string userName,string password, string domain)
{
if (userName == "" || password == "")
{
return false;
}
bool authentic = false;
try
{
DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain,userName, password);
object nativeObject = entry.NativeObject;
authentic = true;
}
catch (DirectoryServicesCOMException) { }
return authentic;
}
我想变成这样:
private bool Authenticate(string userName,string password, string domain, string group)
【问题讨论】:
-
您可能为此任务使用了错误的 API。您是否正在为应用程序编写身份验证代码?如果是这样,应该有一个更简单的 API 可以使用。例如,在 ASP.NET 中,您可以使用 Page.User 对象访问此信息。还是应用程序的目的实际上是查询 Active Directory?
标签: c# authentication active-directory authorization