我的登錄窗口使用LDAP對用戶進行身份驗證。但是,在驗證時,它總是返回false。wpf - 驗證時LDAP始終返回false
下面是驗證代碼,我從CodeProject上了:
public bool fnValidateUser()
{
bool validation;
try
{
LdapConnection lcon = new LdapConnection
(new LdapDirectoryIdentifier((string)null, false, false));
NetworkCredential nc = new NetworkCredential(Environment.UserName,
txtPassword.SecurePassword, Environment.UserDomainName);
lcon.Credential = nc;
lcon.AuthType = AuthType.Negotiate;
// user has authenticated at this point,
// as the credentials were used to login to the dc.
lcon.Bind(nc);
validation = true;
}
catch (LdapException)
{
validation = false;
}
return validation;
}
txtPassword.SecurePassword
是PasswordBox。當我輸入我的密碼/ PIN並點擊登錄時,只要驗證爲false,它就會顯示MessageBox。
我在做什麼錯?
UPDATE:的異常指示「的LDAP服務器不可用」,在這條線lcon.Bind(nc);
添加一個日誌來捕捉異常,以及你作爲異常得到了什麼? – Dinesh
@Dinesh我剛剛添加了它 – bruh1234
根據此例外情況,您的LDAP服務器已關閉或根本沒有連接。 – Dinesh