在我的 asp.net mvc4 Web 应用程序中,我执行了以下身份验证机制。要有一个登录屏幕,用户可以在其中输入他们的 AD 用户名和密码,然后我将针对我们的 LDAP 服务器验证用户凭据。我的登录操作方法是:-
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
MembershipProvider domainProvider;
domainProvider = Membership.Providers["ADMembershipProvider"];
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.");
List<String> domains2 = new List<String>();
//code goes here
}
return RedirectToLocal(returnUrl);
}
在应用程序 web.config 中,我定义了以下 provider ,它们代表我们的 Ldap 连接字符串:-
<membership>
<providers>
<add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=4.0.0.0, 
 Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ADConnectionString" connectionUsername="administrator" connectionPassword="*********" attributeMapUsername="sAMAccountName"/>
</providers>
</membership>
<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP://WIN-SPDev.tdmgroup.local/CN=Users,DC=tdmgroup,DC=local"/>
</connectionStrings
但现在我正在启动新的 asp.net mvc5.2.2 Web 应用程序,它正在起诉 UserManager 而不是 FormsAuthntication,现在我的新 asp.net mvc5.2.2 中的默认登录操作方法是:-
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindAsync(model.UserName, model.Password);
if (user != null)
{
await SignInAsync(user, model.RememberMe);
return RedirectToLocal(returnUrl);
}
else
{
ModelState.AddModelError("", "Invalid username or password.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
那么任何人都可以告诉我强制我的 UserManager 针对 Ldap 对用户进行身份验证所需的步骤,就像我对 FormsAuthentication 所做的那样?谢谢
>