2009-06-17 73 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

相關問題