我有代码来验证Active Directory中的用户,这些用户是用Core 1.0编写的,但现在我需要在Core 2.0中编写相同的代码,其中不支持Memebership.ValidateUser()方法。如何在Core 2.0中验证Active Directory用户?请参阅我已有的代码。
[HttpPost]
public ActionResult Index(Users objUser)
{
bool isValid = Membership.ValidateUser(objUser.UserName, objUser.Password);
HttpContext.Session.Add("User", objUser.UserName);
HttpContext.Session.Add("isAthorizedGroup", 1);
if (validateUser(objUser))
{
if (isValid)
{
var identity = new ClaimsIdentity(new[] {
new Claim(ClaimTypes.Name, objUser.UserName),
new Claim(ClaimTypes.NameIdentifier, objUser.UserName ),
}, DefaultAuthenticationTypes.ApplicationCookie);
var ctx = Request.GetOwinContext();
var authManager = ctx.Authentication;
authManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
authManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, identity);
User.Identity.Name.ToString();
return Redirect("/DefaultPage");
}
}
ViewData["ErrorMessage"] = "Invalid Username or Password";
return View();// RedirectToAction("Index", new { msgError = "Invalid Username or Password" });
}