asp.net – 检查Active Directory密码是否与cookie不同
发布时间:2020-05-23 22:57:02 所属栏目:asp.Net 来源:互联网
导读:我有一个asp.net应用程序需要使用表单身份验证将用户登录到Active Directory(Windows身份验证不是具有给定要求的选项). 我正在保存身份验证cookie,如下所示: if (Membership.ValidateUser(model.UserName, model.Password)){ FormsAuthentication.SetAuthCoo
|
我有一个asp.net应用程序需要使用表单身份验证将用户登录到Active Directory(Windows身份验证不是具有给定要求的选项). 我正在保存身份验证cookie,如下所示: if (Membership.ValidateUser(model.UserName,model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName,model.RememberMe);
}
这非常有效,除非cookie在更改其Active Directory密码后对用户进行身份验证. 有没有办法判断用户的密码是否已更改? 我在.NET 4中使用asp.net MVC3 我试过的 如果觉得这个代码应该有效,那么HttpWebResponse永远不会包含任何cookie.不太确定我做错了什么. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Request.Url);
request.CookieContainer = new CookieContainer();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Cookie authCookie = response.Cookies["AuthCookie"];
if (authCookie.TimeStamp.CompareTo(Membership.GetUser().LastPasswordChangedDate) < 0)
{
authCookie.Expired = true;
}
解决方法你的代码应该阅读if (Membership.ValidateUser(model.UserName,model.Password))
{
string userData = DateTime.Now.ToString();
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,username,DateTime.Now,DateTime.Now.AddMinutes(30),isPersistent,userData,FormsAuthentication.FormsCookiePath);
// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket);
// Create the cookie.
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName,encTicket));
}
现在,在验证用户时 HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.value);
if (DateTime.Parse(ticket.UserData) > Membership.GetUser().LastPasswordChangedDate)
{
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 如何接收JSON作为MVC 5操作方法参数
- asp.net – 访问asp. VM外部的网络开发服务器
- asp.net-mvc – 从MVC Controller导出到CSV,View在页面上显
- asp.net – .Net System.Mail.Message添加多个“To”地址
- asp.net – Owin Middleware vs ExceptionHandler vs HttpM
- asp.net – 如何将流excel文件转换为数据表C#?
- 在ASP.Net中获取会话ID
- Asp.Net Identity – 登录后更新声明
- .net – 单个配置密钥的多个值
- asp.net – 如何在web.config中增加执行sql查询的时间
推荐文章
站长推荐
- asp.net-mvc – ViewBag vs Model,在MVC.NET中
- asp.net – 为VS2010和TFS中的团队管理web.confi
- 为什么我不能在我的代码asp.net c#中使用app_cod
- asp.net-web-api – 如何在ASP.NET Web API中设置
- asp.net-mvc – 不要在ASP .NET MVC 4 BundleCon
- asp.net – 如何在回发后阻止关闭模态弹出窗口(M
- asp-classic – 如何在经典ASP中将数据POST到远程
- .net – 修改MVC 5中的密码长度
- asp.net – 如何使用占位符属性与Html.EditorFor
- asp.net – 什么是Kestrel(vs IIS/Express)
热点阅读
