【问题标题】:userprinciple.FindByIdentity succeeds on one server but not anotheruserprincipal.FindByIdentity 在一台服务器上成功,但在另一台服务器上没有成功
【发布时间】:2012-06-30 03:32:38
【问题描述】:

我的任务是将一些 c# v4 应用程序从一台服务器迁移到另一台服务器,但我遇到了其中一种 aspx 表单的问题。

表单调用了一个类以在其代码隐藏文件中搜索 AD 用户。它调用的方法如下。

    public UserPrincipal GetADUser(string samAccountName)
        {
        try
        {
            UserPrincipal user = UserPrincipal.FindByIdentity(AD.domainContext, samAccountName);
            return user;
        }
        catch(Exception ex)
        {
            throw new Exception(" Cant perform this operation:-"+ex.Message);
        }
    }

AD.domainContext 定义如下

private static PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, ConfigurationHandler._ADDomain);

我的问题是该方法适用于我的 2 台服务器(VS Dev 和当前运行我从中迁移的代码的服务器),并在我试图迁移到的服务器上引发异常。所有服务器都是相同的环境 Windows Server 2k8 R2 运行 iis 7.5

抛出的错误是

无法执行此操作:-发生操作错误。

我已经搜索并发现了以下 stackoverflow 问题,但似乎没有一个可以解决问题

System.DirectoryServices.AccountManagement.PrincipalContext and Impersonation in a WCF service

Active Directory COM Exception - An operations error occurred (0x80072020)

有没有人知道是什么导致这个错误在一个环境而不是任何其他环境中引发?

我尝试调试代码,它在 VS 调试中运行良好,但是当代码部署到所述服务器时,我遇到了问题。

任何帮助、想法、想法将不胜感激。

如果我忘记包含任何内容,我很乐意详细说明所提供的任何信息。

提前致谢

尼古拉斯

【问题讨论】:

    标签: c# asp.net active-directory


    【解决方案1】:

    对于面临类似问题的任何其他人,解决方案似乎是需要提供用户名和密码才能查询 AD,除非您在 IIS 中打开了用户假冒。

    只需用以下方法修改我的方法即可解决问题

    private static PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, null,ConfigurationHandler._ADDomain, ConfigurationHandler._ADUser, ConfigurationHandler._ADPassword);
    

    谢谢

    尼古拉斯

    【讨论】:

      猜你喜欢
      • 2010-12-30
      • 1970-01-01
      • 1970-01-01
      • 2013-12-10
      • 2015-12-23
      • 1970-01-01
      • 1970-01-01
      • 2012-01-25
      • 1970-01-01
      相关资源
      最近更新 更多