【发布时间】:2019-10-11 19:44:16
【问题描述】:
我正在使用以下代码检查 AD 中是否存在用户名,当我在 VS 中调试应用程序时,它会抛出“用户名或密码不正确”异常,但如果我在 IIS 中发布完全相同的代码,它可以工作很好,按预期返回真或假
private bool UserExist(string path, string username)
{
DirectoryEntry entry = new DirectoryEntry(path);
try
{
object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
SearchResult result = search.FindOne();
if (null == result)
{
return false;
}
else
{
return true;
}
}
catch (Exception ex)
{
throw ex;
}
}
【问题讨论】:
-
IIS 应用程序池在什么凭据下运行?它是否比您的帐户拥有更多的 AD 访问权限?
obj的意义何在?我没有看到它在您的代码中的任何地方使用。 -
在 iis 在默认的“ApplicationPoolIdentity”下运行,而 obj 是的,它什么也不做,如果我删除该行仍然抛出异常,实际上我正在连接到两个 AD 和一个在 IIS 和 VS 中都可以正常工作,但另一个不能
标签: c# asp.net-mvc-4 iis active-directory