我使用Hosting Environment类下的DirectorySearch.FindOne()从Active Directory中检索用户详细信息。它在localhost中工作正常,但是当我把它放在服务器上时,它会抛出一个错误。DirectorySearch.Findone()在服务器中部署时不起作用?
即使在IIS中,我已将我的ApplicationPoolIdentity更改为Network service,但也没有用。
我是否需要在web.config中添加其他内容才能使其正常工作。以下是我的代码。
protected void btnSubmit_Click(object sender, EventArgs e)
{
strrUser = txtUserName.Text;
strPassword = txtPWD.Text;
role = txtRole.SelectedItem.Value;
//string selectedrole = txtRole.SelectedValue;
using (PrincipalContext pContext = new PrincipalContext(ContextType.Domain))
{
if (pContext.ValidateCredentials(strrUser, strPassword))
{
SearchResult result;
using (HostingEnvironment.Impersonate())
{
DirectorySearcher ds = new DirectorySearcher();
ds.SearchScope = SearchScope.Subtree;
ds.ReferralChasing = ReferralChasingOption.All;
ds.Filter = String.Format("(&(objectCategory=person)(sAMAccountName={0}))", strrUser);
result = ds.FindOne();
}
if (result != null)
{
DirectoryEntry entry = result.GetDirectoryEntry();
employeeID = entry.Properties["physicaldeliveryofficename"].Value.ToString();
username = entry.Properties["displayName"].Value.ToString();
}
'在服务器中抛出错误'错误是什么? – Nathan
描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。 异常详细信息:System.Runtime.InteropServices.COMException:指定的域不存在或无法联系。 – user3585252
以上是我得到的错误..但根据我的知识,它试图访问我想要的相同somain。此外,同一组编码正在为另一个托管在另一个端口中同一服务器上的应用程序成功运行。但我不认为它的端口问题作为登录页面,然后主要凭证验证使用主要上下文类ae工作良好,但不findone() – user3585252