【问题标题】:Support Windows Server 2016 Active Directory?支持 Windows Server 2016 活动目录?
【发布时间】:2018-10-11 10:13:17
【问题描述】:

我有一个使用 Windows Active Directory 获取当前 Windows 帐户名称的 Winform 客户端。

有什么方法可以知道此解决方案是否可以在不进行设置的情况下与新的 Windows Server 2016 Active Directory 一起使用?

客户端代码

            public string GetCurrentActiveDirectoryAccountName()
            {
                var windowsName = WindowsIdentity.GetCurrent().Name;
                var index = windowsName.LastIndexOf("\\");
                if (index > 0)
                    windowsName = windowsName.Substring(index + 1);

                return windowsName;
            }

        public void AuthenticateActiveDirectoryAccount(string username, string password)
        {
            //Hidden code to setup variables 

            if (ADUserName.Length > 0)
                context = new PrincipalContext(ContextType.Domain, ADServer, ADUserName, ADUserPassword);
            else
                context = new PrincipalContext(ContextType.Domain, ADServer);

            using (context)
            {
                if (!context.ValidateCredentials(account, password))
                    //Hidden code to throw exception
            }
        }

        public string CheckActiveDirectoryAccount(string account)
        {
            ///Hidden code to setup variables

            if (ADUserName.Length > 0)
                context = new PrincipalContext(ContextType.Domain, ADServer, null, ADUserName, ADUserPassword);
            else
                context = new PrincipalContext(ContextType.Domain, ADServer);

            using (context)
            {
                if ((user = UserPrincipal.FindByIdentity(context, account)) == null)
                {
                    if (account.Contains("\\"))
                    {
                        userPrincipalNameList = user.UserPrincipalName.Split('\\').ToList();

                        if (userPrincipalNameList.Count > 0)
                            user = UserPrincipal.FindByIdentity(context, userPrincipalNameList[0]);
                    }
                }

                if (user != null)
                {
                    using (user)
                    {
                        userAccount = user.SamAccountName;
                        return userAccount.ToLower();
                    }
                }
            }
            return string.Empty;
        }

【问题讨论】:

    标签: c# authentication active-directory principalcontext


    【解决方案1】:

    Microsoft 在向后兼容方面历来非常谨慎。这就是您仍然可以在 Windows 10 中运行 DOS 程序的原因。

    使用 AD,它们通常不会删除功能。他们只添加它们。查看这篇文章,了解 AD for Server 2016 的新增功能:https://docs.microsoft.com/en-us/windows-server/identity/whats-new-active-directory-domain-services

    我希望所有这些都适用于在 Server 2016 上运行的 AD。

    【讨论】:

      【解决方案2】:

      我不得不按预期使用 Microsoft Windows Server 2016 设置测试,我的 AD 集成工作正常。

      【讨论】:

        猜你喜欢
        • 2019-07-05
        • 1970-01-01
        • 2013-02-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-14
        • 1970-01-01
        相关资源
        最近更新 更多