在我的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中定义以下提供程序,它代表我们的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吗? 感谢
&GT;