久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

檢查 Active Directory 密碼是否與 cookie 不同

Check if Active Directory password is different from cookie(檢查 Active Directory 密碼是否與 cookie 不同)
本文介紹了檢查 Active Directory 密碼是否與 cookie 不同的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個 asp.net 應用程序,它需要使用表單身份驗證將用戶登錄到 Active Directory(Windows 身份驗證不是具有給定要求的選項).

I have an asp.net app which needs to log users into Active Directory using forms authentication (windows authentication isn't an option with the given requirements).

我像這樣保存身份驗證 cookie:

I'm saving authentication cookies like so:

if (Membership.ValidateUser(model.UserName, model.Password))
{
    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
}

這很有效,除了即使用戶更改了 Active Directory 密碼后,cookie 也會對用戶進行身份驗證.

This works great, except that the cookie authenticates the user even after they change their Active Directory password.

有沒有辦法判斷用戶的密碼是否已更改?

Is there a way to tell if the user's password has changed?

我在 .NET 4 中使用 asp.net MVC3

I'm using asp.net MVC3 with .NET 4

我的嘗試

如果覺得這段代碼應該可以工作,但是 HttpWebResponse 永遠不會包含任何 cookie.不太確定我做錯了什么.

If feel like this code should work, however the HttpWebResponse never contains any cookies. Not quite sure what I'm doing wrong.

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();
}

這篇關于檢查 Active Directory 密碼是否與 cookie 不同的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Asp.net System.Web.HttpContext.Current.Session null in global.asax(Asp.net System.Web.HttpContext.Current.Session 在 global.asax 中為 null)
Caught exception is null itself !(捕獲的異常本身為空!)
Is an empty textbox considered an empty string or null?(空文本框被視為空字符串還是 null?)
System.DirectoryServices - The server is not operational(System.DirectoryServices - 服務器無法運行)
Accessing Active Directory from ASP.Net MVC using C#(使用 C# 從 ASP.Net MVC 訪問 Active Directory)
How can I find out which server hosts LDAP on my windows domain?(如何找出在我的 Windows 域上托管 LDAP 的服務器?)
主站蜘蛛池模板: 午夜精品一区二区三区在线观看 | 国产丝袜一区二区三区免费视频 | 国产精品高潮呻吟久久 | 日韩中文字幕在线不卡 | 人人干免费| 精品视频在线免费观看 | 成人av一区 | 国产羞羞视频在线观看 | 97国产精品视频人人做人人爱 | 韩日一区二区三区 | 99re99| 午夜电影福利 | 国产999精品久久久 日本视频一区二区三区 | 亚洲精品一级 | 天天天天操 | 免费看欧美一级片 | a毛片| 成人在线一区二区三区 | 成人片在线看 | 亚洲综合久久网 | 欧美一区二区三区久久精品 | 国产精品一区在线 | 狠狠干五月天 | www.中文字幕.com | 久久国产精品久久久久久久久久 | 99热精品在线 | 一区二区三区在线免费观看 | 欧美日韩成人 | 欧美在线视频一区二区 | 欧美一级黄视频 | 国产精品污www一区二区三区 | 国产区免费视频 | 日本视频在线播放 | 欧美激情a∨在线视频播放 成人免费共享视频 | 亚洲精品国产第一综合99久久 | 日韩中文字幕在线观看视频 | 午夜影院普通用户体验区 | 久草a√ | 亚州精品天堂中文字幕 | 国产一区二区三区四区在线观看 | 在线观看av网站永久 |