【发布时间】:2017-04-06 09:21:51
【问题描述】:
我已经使用 LDAP 在 ASP.NET MVC 5 中实现了 Active Directory 身份验证。我想知道如何获取用户的
- 帐户已锁定(布尔值)
- 密码已过期(布尔值)
- 密码到期日期(日期时间)
这是我当前的代码:
using System.Web.Mvc;
using System.Web.Security;
using MvcApplication.Models;
[HttpPost]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (!this.ModelState.IsValid)
{
return this.View(model);
}
if (Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
if (this.Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return this.Redirect(returnUrl);
}
return this.RedirectToAction("Index", "Home");
}
this.ModelState.AddModelError(string.Empty, "The user name or password provided is incorrect.");
return this.View(model);
}
public ActionResult LogOff()
{
FormsAuthentication.SignOut();
return this.RedirectToAction("Index", "Home");
}
【问题讨论】:
-
我希望尽可能多地使用 System.Web.Security。通过它,我能够检索 AccountLocked。现在我需要知道如何将我的 LDAP Activedirectory 实例化为一个对象,以便我可以获得它的对象属性。有人知道如何实现吗?
标签: c# asp.net asp.net-mvc active-directory