[英]Form Authentication against our Active Directory’s LDAP server will always return invalid username/password
我正在處理一個asp.net mvc-5 Web應用程序。 我正在使用asp.net成員資格提供程序通過表單身份驗證針對我們的ldap服務器對用戶進行身份驗證。
這是登錄操作方法:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
MembershipProvider domainProvider;
domainProvider = Membership.Providers["TestDomain1ADMembershipProvider"];
if (ModelState.IsValid)
{
// Validate the user with the membership system.
if (domainProvider.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
}
else
{
// Response.Write("Invalid UserID and Password");
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
return RedirectToLocal(returnUrl);
}
return View(model);
}
還有我為ldap定義了<providers>
和<connection string>
的web.config文件:
<providers>
<add name="TestDomain1ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=4.0.0.0, 
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="DomainConnectionString" connectionUsername="*****\administrator" connectionPassword="*****" attributeMapUsername="sAMAccountName"/>
</providers>
和
<connectionStrings>
<add name="DomainConnectionString" connectionString="LDAP://WIN-SPDev.tgroup.local/OU=Domain Controllers,DC=tgroup,DC=local"/>
</connectionStrings>
但是現在,當用戶輸入用戶名/密碼時, domainProvider.ValidateUser(model.UserName, model.Password)
始終返回false。
任何人都可以對此提出建議嗎?
謝謝
在以下情況下,提供正確的憑據時ValidateUser方法可能返回false:
1.由於失敗的登錄嘗試太多,用戶帳戶被目錄服務器鎖定。 在目錄的鎖定持續時間過去之前,用戶將無法登錄。
2.如果EnablePasswordReset屬性為true,則如果用戶提供錯誤的密碼答案的次數過多,則該用戶帳戶將被鎖定。 在PasswordAnswerAttemptLockoutDuration屬性中指定的時間過去之后,用戶的帳戶將解鎖。
3.用戶必須存在於連接字符串中指定的容器中。 為位於不同容器或不同域中的用戶帳戶提供了有效的憑據。 用戶必須存在於連接字符串中指定的容器中。
可能您需要輸入用戶名作為DOMAIN\\username
(請參見第3項)?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.