2013-04-23 22 views
0

我是stachoverflow的新用戶,我正在開發一個Intranet網絡應用程序,它從Active Directory中驗證用戶身份,但我得到的問題來檢索從本地服務器上正常工作的活動目錄組中的數據(所有用戶名)。 它在IIS上發生異常錯誤 - System.DirectoryServices.DirectoryServicesCOMException:登錄失敗:未知的用戶名或密碼錯誤。 在啓用IIS的Windows身份驗證和其他被禁用我可以從本地服務器上的活動目錄組中檢索所有用戶名,但是在IIS上顯示出現異常錯誤

My code is: 
Web.config file: 
<authentication mode="Windows"> 
      <forms loginUrl="~/TTracker/Login.aspx" timeout="600"></forms> 
     </authentication> 

<authorization> 
      <deny users="?"/> 
      <allow users="*" /> 


     </authorization> 
    <identity impersonate="true" /> 


Code for retrieving data: 

using System.DirectoryServices; 
using System.DirectoryServices.AccountManagement; 
using (HostingEnvironment.Impersonate()) 
      { 
       DropDownList1.Items.Add(new ListItem("-Select-", "")); 
       string grpname = "Group1";     
       PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "domain"); 
       GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, grpname); 
       if (grp != null) 
       { 
        foreach (Principal p in grp.GetMembers(false)) 
        { 
         DropDownList1.Items.Add(p.SamAccountName + "-" + p.DisplayName); 

        } 
        grp.Dispose(); 
        ctx.Dispose(); 
        Console.ReadLine(); 
       } 
       else 
       { 
        Console.WriteLine("We did not find that group."); 
        Console.ReadLine(); 
       } 
      } 


this is my code for retrieving data from active directory which works fine locally but not works on IIS. 

It will be great help if any one solve this issue. 

Thanks in advance. 

回答

0

它與模擬有關。

請檢查以下內容

我們可以模擬一個帳戶以使用AD進行處理。

ASP.NET模擬 http://msdn.microsoft.com/en-us/library/aa292118(VS.71).aspx 並閱讀本文檔。

HOWTO:通過C#(幾乎)一切在Active Directory中 http://www.codeproject.com/KB/system/everythingInAD.aspx

+0

Nipun您好,感謝烏拉圭回合的答案,但我沒有得到爲什麼它,而不是在驗證時檢索從Active Directory數據時只發生針對活動目錄。 – Chetan 2013-05-02 13:08:52

+0

如果您看到Chetan廣泛,認證和數據檢索是兩件不同的事情。 認證是可以的,但是AD有很多規則來檢索已經定義和可以定義的數據。 – 2013-05-03 05:49:28

相關問題