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

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

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

問題描述

我有一個 asp.net 應(yīng)用程序,它需要使用表單身份驗證將用戶登錄到 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

我的嘗試

如果覺得這段代碼應(yīng)該可以工作,但是 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;
}

推薦答案

你的代碼應(yīng)該閱讀

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

現(xiàn)在,當(dāng)驗證用戶時

HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.value);
if (DateTime.Parse(ticket.UserData) > Membership.GetUser().LastPasswordChangedDate)
{
    FormsAuthentication.SignOut();
    FormsAuthentication.RedirectToLoginPage();
}

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

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

相關(guān)文檔推薦

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 - 服務(wù)器無法運行)
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 的服務(wù)器?)
主站蜘蛛池模板: 亚洲天天干| 日日摸天天添天天添破 | 久久999 | 久久久黄色| 在线精品亚洲欧美日韩国产 | 一区二区三区四区在线免费观看 | 婷婷丁香激情 | 国产激情视频网站 | 极品销魂美女一区二区 | 免费观看一级特黄欧美大片 | 伊人色综合久久天天五月婷 | 国产乱码久久久 | 国产成人免费视频网站视频社区 | 国产亚洲精品一区二区三区 | 久久精品亚洲欧美日韩精品中文字幕 | 午夜天堂精品久久久久 | 久久久影院 | 91视频入口| 国产又色又爽又黄又免费 | 亚洲精品久久久久久首妖 | 欧产日产国产精品视频 | 在线激情视频 | 99re6在线视频精品免费 | 中日韩av | 国产一区二区三区 | av国产精品 | 欧美激情精品久久久久久免费 | 一级毛片在线看 | 欧美精品久久久久久久久久 | 亚洲美女天堂网 | av在线免费观看网址 | 亚洲日韩中文字幕一区 | www日日日 | 亚洲高清三级 | 日韩欧美在线观看 | 日韩有码一区 | 免费国产视频在线观看 | h片免费在线观看 | 武道仙尊动漫在线观看 | www.精品一区| 在线亚洲免费 |