2009-06-17 74 views
0

我收到一个基于Web的应用程序的错误,该应用程序允许企业Intranet用户更新其活动目录详细信息(电话号码等)。从Web应用程序错误更新Active Directory

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)代码应该传递正确的模拟信息(包括安全令牌)到活动目录。

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) 

该代码在我们的开发域中正常工作,但在我们的生产域中不起作用。任何人都可以协助解决这个问题吗?

回答

0

问题不在于代码,而是服务器在域上如何设置。出于某种原因,网络管理员未在活动目录中选择“用于授权的信任计算机”选项。

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

0

这听起来像你可能有一个重复的SPN问题?

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

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

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

0

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

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

+0

感谢您的提示。我检查了这两种环境,我只是“域用户”组的成员。 – Kane 2009-06-17 05:39:23

相关问题