【问题标题】:Updating Active Directory from Web Application Error从 Web 应用程序错误更新 Active Directory
【发布时间】:2010-11-03 13:22:46
【问题描述】:

我在基于 Web 的应用程序中收到错误消息,该应用程序允许公司 Intranet 用户更新其活动目录详细信息(电话号码等)。

Web 应用程序托管在运行 Windows Server 2003 (SP1) 的 IIS6 上。 IIS 网站正在使用 NTLM 身份验证,并且该网站已启用集成安全性。 IIS 应用程序池使用“网络服务”帐户运行。

web.config 包含以下元素

<LdapConfigurations server="xxx.internal" root="OU=Staff Accounts,DC=xxx,DC=internal" domain="xxx" />
<identify impersonate=”true” />

不需要 Active Directory 委派,因为以下 C# (.NET 3.5) 代码应将正确的模拟详细信息(包括安全令牌)传递到 Active Directory。

public void UpdateData(string bus, string bus2, string fax, string home, string home2, string mob, string pager, string notes)
{
    WindowsIdentity windId = (WindowsIdentity)HttpContext.Current.User.Identity;
    WindowsImpersonationContext ctx = null;

    try
    {
        ctx = windId.Impersonate();

        DirectorySearcher ds = new DirectorySearcher();
        DirectoryEntry de = new DirectoryEntry();

        ds.Filter = m_LdapUserFilter;

        // i think this is the line causing the error
        de.Path = ds.FindOne().Path;

        this.AssignPropertyValue(bus, ADProperties.Business, ref de);
        this.AssignPropertyValue(bus2, ADProperties.Business2, ref de);
        this.AssignPropertyValue(fax, ADProperties.Fax, ref de);
        this.AssignPropertyValue(home, ADProperties.Home, ref de);
        this.AssignPropertyValue(home2, ADProperties.Home2, ref de);
        this.AssignPropertyValue(mob, ADProperties.Mobile, ref de);
        this.AssignPropertyValue(pager, ADProperties.Pager, ref de);
        this.AssignPropertyValue(notes, ADProperties.Notes, ref de);

        // this may also be causing the error?
        de.CommitChanges();
    }
    finally
    {
        if (ctx != null) 
        {
            ctx.Undo();
        }
    }
}

private void AssignPropertyValue(string number, string propertyName, ref  DirectoryEntry de)
{
    if (number.Length == 0 && de.Properties[propertyName].Value != null)
    {
        de.Properties[propertyName].Remove(de.Properties[propertyName].Value);
    }
    else if (number.Length != 0)
    {
        de.Properties[propertyName].Value = number;
    }
}

可以毫无问题地从 Active Directory 中检索用户详细信息,但是在更新用户 AD 详细信息时会出现问题。将显示以下异常消息。

 System.Runtime.InteropServices.COMException (0x80072020): An operations error occurred. 
       at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) 
       at System.DirectoryServices.DirectoryEntry.Bind() 
       at System.DirectoryServices.DirectoryEntry.get_AdsObject() 
       at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) 
       at System.DirectoryServices.DirectorySearcher.FindOne()    
       at xxx.UpdateData(String bus, String bus2, String fax, String home, String home2, String mob, String pager, String notes) 
       at xxx._Default.btnUpdate_Click(Object sender, EventArgs e)

代码在我们的开发域中运行良好,但在我们的生产域中却不行。谁能帮忙解决这个问题?

【问题讨论】:

    标签: c# asp.net security active-directory


    【解决方案1】:

    这很可能是权限问题 - 这里有很多关于模拟和委托及其变幻莫测的文章:http://support.microsoft.com/default.aspx?scid=kb;en-us;329986 和这里:http://support.microsoft.com/default.aspx?scid=kb;en-us;810572

    【讨论】:

      【解决方案2】:

      听起来您可能遇到了重复的 SPN 问题?

      这就是为什么我认为这可能是一个问题:

      1. 它适用于您的开发环境(假设它也使用网络服务,并且在同一个域中)
      2. 您已在您的网络配置中模拟。
      3. 当存在重复的 SPN 时,它会使安全令牌失效,因此即使您已在代码中正确创建它,AD 也不“信任”该服务器来模拟,因此接收请求的服务器对进行更改AD(在您的 DC 上)收到请求但随后将其丢弃,因为尚未在 AD 中的计算机帐户上应用延迟权限,或 SPN 问题(重复或不正确的计算机名称/域名)

      或者至少在我的经验中这是 10 次中的 9 次。

      【讨论】:

        【解决方案3】:

        我想问题在于它在开发环境中工作,因为当你在那里启动你的 webapp 时,你使用你的个人帐户运行它,该帐户可能有权写入 AD。

        在生产环境中,您必须确保运行您的 webapp(网络服务帐户)的进程也有权更新 AD。在我看来,这可能是问题所在,因为我曾经遇到过类似的问题。

        【讨论】:

        • 感谢您的提示。我在两种环境中都进行了检查,我只是“域用户”组的成员。
        【解决方案4】:

        问题不在于代码,而在于如何在域中设置服务器。由于某种原因,网络管理员没有在活动目录中选择“信任计算机以进行委派”选项。

        幸好问题不是“双跳”问题 :)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-09-22
          • 2016-02-04
          • 2019-12-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多