2009-02-03 76 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; 
      } 
     } 
    } 
}