我在MVC项目中使用ASP.NET Identity 2.0和LDAP身份验证,我的Loing方法如下所示。在第一步,我检查用户是否在LDAP中进行了身份验证,但我需要检测LDAP中是否没有用户或凭据是否错误,以便向用户返回正确的消息。我怎么能这样做?
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
ApplicationGroupManager groupManager = new ApplicationGroupManager();
// Validate the user using LDAP
if (Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
// FormsAuthentication.SetAuthCookie(model.UserName, false);
//code omitted for brevity
if (this.Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return this.Redirect(returnUrl);
//return RedirectToLocal(returnUrl);
}
return this.RedirectToAction("Index", "Issue");
}
else
{
ModelState.AddModelError("", "Wrong credentials");
return this.View(model);
}
}