Active Directory PrincipalContext.ValidateCredentials域消除歧义

Gar*_*eld 4 c# multiple-domains active-directory

我正在处理两个域 - 一个是可信域.一个域上可能有JohnSmith,另一个域上可能有另一个JohnSmith.这两个人都需要登录我的应用程序.

我的问题:我传入哪个域并不重要 - 这段代码返回true!我怎么知道JohnSmith正在登录哪个?

    static public bool CheckCredentials(
        string userName, string password, string domain)
    {
        using (var context = new PrincipalContext(ContextType.Domain, domain))
        {
            return context.ValidateCredentials(userName, password);
        }
    }
Run Code Online (Sandbox Code Playgroud)

JPB*_*anc 5

在ValidateCredentials与作品userPrincipalName,你也许可以尝试建立相结合的登录和创建用户名域中的第一个参数(用户名)JohnSmith@dom1.com对JohnSmith@dom2.com.