2009-02-03 74 views
0

我在Windows域(服務器是Windows 2003,IIS6,NTFS權限)上有一個Intranet服務器。它位於域Domain01上。我有來自同一個林中訪問此Intranet的兩個域的用戶:Domain01和Domain02(DC也運行Windows 2003)。目前,需要用戶通過輸入登錄: Domain01 \用戶名或用戶名@ Domain01簡單登錄多域內部網?

我的用戶是完全徹底地通過讓每個登錄時輸入的域名混淆 有什麼辦法。只需輸入他們的用戶名和密碼而無需登錄即可登錄?例如,讓服務器默認嘗試Domain01,如果登錄失敗嘗試Domain02?

注意:如果可能的話,我想通過IIS或服務器設置來做到這一點,而不是通過編程方式(僅供參考,我使用的是ASP.NET 2.0)。

+0

你可以編寫這樣的代碼,假設你有與Intranet應用程序(你沒有說明它的任何細節)的控制權。你還沒有說明域名是什麼(Win2008或Win2003等)以及這兩個域名之間的關係。 – 2009-02-03 16:20:13

回答

2

是的。通常我所做的是使用提供的用戶名作爲sAMAccountName進行全局目錄搜索。用PrincipalSearcher做這件事需要獲取底層的DirectorySearcher並替換它的SearchRoot。一旦找到相應的用戶對象,我就從用戶對象的路徑中提取域,並將其用作身份驗證步驟的域。你如何做認證取決於你需要做什麼。如果您不需要模擬,則可以使用PrincipalContext.ValidateCredentials確保用戶名/密碼匹配使用與您先前找到的用戶帳戶的域匹配的PrincipalContext。如果你需要冒充this reference

// NOTE: implement IDisposable and dispose of this if not null when done. 
private DirectoryEntry userSearchRoot = null; 
private UserPrincipal FindUserInGlobalContext(string userName) 
{ 
    using (PrincipalSearcher userSearcher = new PrincipalSearcher()) 
    { 
     using (PrincipalContext context 
       = new PrincipalContext(ContextType.Domain)) 
     { 
      userSearcher.QueryFilter = new UserPrincipal(context); 
      DirectorySearcher searcher 
       = (DirectorySearcher)userSearcher.GetUnderlyingSearcher(); 

      // I usually set the GC path from the existing search root 
      // by doing some string manipulation based on our domain 
      // Your code would be different. 
      string GCPath = ...set GC path.. 

      // lazy loading of the search root entry. 
      if (userSearchRoot == null) 
      { 
       userSearchRoot = new DirectoryEntry(GCPath); 
      } 

      searcher.SearchRoot = userSearchRoot; 
      using (PrincipalContext gcContext = 
        new PrincipalContext(ContextType.Domain, 
              null, 
              GCPath.Replace("GC://","")) 
      { 
       UserPrincipal userFilter = new UserPrincipal(gcContext); 
       userFilter.SamAccountName = userName; 
       userSearcher.QueryFilter = userFilter; 
       return userSearcher.FindOne() as UserPrincipal; 
      } 
     } 
    } 
}