【发布时间】:2015-02-05 01:08:51
【问题描述】:
我正在使用默认的 ASP.NET 4.5 框架的 ASP.NET MVC 5 项目模板。它配置了身份认证框架。
我想在我的项目中使用 Window 的 Active Directory,所以我关注了这篇文章 - http://www.schiffhauer.com/mvc-5-and-active-directory-authentication/
在我的 AccountController 的登录方法中,我有
if (Membership.ValidateUser(model.Email, model.Password))
{
CustomFormsAuthentication.SetAuthenticationCookie(model.Email, model, model.RememberMe);
return RedirectToAction("Index", "Home");
}
CustomFormsAuthentication 类的位置
public static class CustomFormsAuthentication
{
public static void SetAuthenticationCookie(string username, object obj, bool isPersistent)
{
const int version = 1;
var json = new JavaScriptSerializer().Serialize(obj);
var cookieStoreTime = isPersistent ? DateTime.Now.AddDays(7): DateTime.Now.AddDays(1);
var ticket = new FormsAuthenticationTicket(version, username, DateTime.Now, cookieStoreTime, isPersistent, json);
HttpContext.Current.Response.Cookies.Set(new HttpCookie(FormsAuthentication.FormsCookieName,
FormsAuthentication.Encrypt(ticket)) {Expires = cookieStoreTime});
}
}
但用户从未经过身份验证。 User.Identity.IsAuthenticated 仍然显示为 false。
我该怎么办?
【问题讨论】:
标签: c# asp.net asp.net-mvc