我有一个Winform客户端,它使用Windows Active Directory获取当前Windows帐户名。
是否有任何方法可以知道此解决方案是否可以在不设置新的Windows Server 2016的情况下使用?
客户端代码
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;
}发布于 2018-10-24 07:43:50
我不得不像预期的那样在2016上设置一个测试,我的AD集成工作也一样好。
发布于 2018-10-16 12:48:12
从历史上看,微软在向后兼容方面相当谨慎。这就是为什么您仍然可以在Windows 10中运行DOS程序的原因。
对于AD,它们通常不会删除功能。他们只会加进去。看一看这篇文章,看看AD for Server 2016中的新内容:https://learn.microsoft.com/en-us/windows-server/identity/whats-new-active-directory-domain-services
我希望所有这些都能与运行在Server 2016上的AD一起工作。
https://stackoverflow.com/questions/52757528
复制相似问题