本文介绍了无法联系服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public static bool ValidateActiveDirectoryLogin(string Domain, string Username, string Password)
{
bool isValid = false;
try
{
string ipAddress = "";
if (Dns.GetHostAddresses(Dns.GetHostName()).Length > 0)
{
ipAddress = Dns.GetHostAddresses(Dns.GetHostName())[0].ToString();
}
//create a "principal context" - e.g. your domain (could be machine, too)
//using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, Domain))
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, Domain, "DC=estagioit,DC=local"))
{
// validate the credentials
isValid = pc.ValidateCredentials(Username, Password);
}
}
catch (Exception ex)
{
isValid = false;
}
return isValid;
}
我的尝试:
What I have tried:
public static bool ValidateActiveDirectoryLogin(string Domain, string Username, string Password)
{
bool isValid = false;
try
{
string ipAddress = "";
if (Dns.GetHostAddresses(Dns.GetHostName()).Length > 0)
{
ipAddress = Dns.GetHostAddresses(Dns.GetHostName())[0].ToString();
}
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, Domain, "DC=estagioit,DC=local"))
{
isValid = pc.ValidateCredentials(Username, Password);
}
}
catch (Exception ex)
{
isValid = false;
}
return isValid;
}
推荐答案
这篇关于无法联系服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!