我們知道表單身份驗證Cookie已加密。所以如何從我的代碼背後讀取表單身份驗證cookie內容。從後面的asp.net代碼讀取表單身份驗證Cookie
if (Request.Cookies[".ASPXAUTH"] != null)
{
HttpCookie myCookie = new HttpCookie(".ASPXAUTH");
}
我們知道表單身份驗證Cookie已加密。所以如何從我的代碼背後讀取表單身份驗證cookie內容。從後面的asp.net代碼讀取表單身份驗證Cookie
if (Request.Cookies[".ASPXAUTH"] != null)
{
HttpCookie myCookie = new HttpCookie(".ASPXAUTH");
}
您可以通過FormsAuthentication
HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
string cookiePath = ticket.CookiePath;
DateTime expiration = ticket.Expiration;
bool expired = ticket.Expired;
bool isPersistent = ticket.IsPersistent;
DateTime issueDate = ticket.IssueDate;
string name = ticket.Name;
string userData = ticket.UserData;
int version = ticket.Version;
如何從票證中提取數據....假設我創建如下的一種身份驗證cookie。的FormsAuthenticationTicket票=新的FormsAuthenticationTicket( 1, 用戶名, DateTime.Now, DateTime.Now.AddMinutes(30), isPersistent, 的UserData, FormsAuthentication.FormsCookiePath);那麼解密後如何從票證中獲得上述數據? plzz指導我.......謝謝 – Thomas
解密之後,您可以直接在票證上訪問屬性。這顯示屬性列表:http://msdn.microsoft.com/en-us/library/system.web.security.formsauthenticationticket.aspx。我用一個訪問票據數據的例子更新了答案。 – RyanW
只是一個錯字:ticket.IsPersistant應ticket.IsPersistent – Raghav
可能重複http://stackoverflow.com/questions/2921387/get-the-aspxauth-cookie-value-programatically提供的解密方法訪問票 – xsari3x