在IIS中托管时,活动目录搜索不起作用 [英] Active directory search does not work when hosted in IIS

查看:82
本文介绍了在IIS中托管时,活动目录搜索不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的项目中有一个活动目录搜索,当我从visual studio运行时工作正常。但是,当我在IIS中托管相同的东西时,它不起作用。



有人可以帮忙吗?



以下是我使用的代码

Hi all,

I have a active directory search in my project and works fine when i run from visual studio. But when i host the same in IIS it does not work.

Can anybody please help?

The following is the code i use

System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry(string.Format("LDAP://{0}", Environment.UserDomainName));
System.DirectoryServices.DirectorySearcher dSearch = new System.DirectoryServices.DirectorySearcher(entry);
//dSearch.Filter = string.Format("(&(objectClass=User)(|(cn={0})(sAMAccountName={0})))", objUserInformation.EmpID);
dSearch.Filter = string.Format("(&(objectClass=User)(|(cn={0})(sAMAccountName={0})))", "E455321");

dSearch.PropertiesToLoad.Add("directReports");

dt.Columns.Add("Name");

dtEmpDet.Columns.Add("Eid");
dtEmpDet.Columns.Add("Email");
this.ClientSideAlertMessage("After col add");

foreach (object objProperty in dSearch.FindOne().Properties["directReports"])
{
    var objProperty1 = objProperty.ToString();
    var subordinatename = objProperty1.Split(',').Select(pair => pair.Split('=').LastOrDefault()).ToArray().GetValue(0);
    System.DirectoryServices.AccountManagement.PrincipalContext ctx = new System.DirectoryServices.AccountManagement.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType.Domain);
    System.DirectoryServices.AccountManagement.UserPrincipal user = System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(ctx, System.DirectoryServices.AccountManagement.IdentityType.DistinguishedName, objProperty1);
    
    //Adding rows to the datatable
    DataRow dr;
    dr = dt.NewRow();
    dr[0] = user.DisplayName;
    dt.Rows.Add(dr);
    DataRow drEmpDet;
    drEmpDet = dtEmpDet.NewRow();
    UserManager objUserManager = new UserManager();
    drEmpDet[0] = objUserManager.GetEmpEid(user.EmailAddress);
    drEmpDet[1] = user.EmailAddress;
    dtEmpDet.Rows.Add(drEmpDet);
}





提前致谢,

Joseph



Thanks in advance,
Joseph

推荐答案

实际上,当我从Visual Studio运行时,它使用了不同的域名,而当我从IIS运行时则使用了另一个域名。



I确定并清除它。



感谢您的所有评论
Actually the domain name it took a different one when i run from Visual Studio and a different one when i run from IIS.

I identified it and got it cleared.

Thanks all for your comments


这篇关于在IIS中托管时,活动目录搜索不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆