2011-05-24 27 views
1

當有人登錄我的應用程序,他們檢查了「記住我」複選框時,我設置了createPersistentCookie = true,以便當他們回來時不需要再次登錄。然而,有時候我需要使用FormsAuthentication.SetAuthCookie(NewUserName, [true/false]),所以我怎麼知道它們是否最初將createPersistentCookie設置爲true,所以我可以保持它與登錄時相同?如何在ASP.NET窗體身份驗證中檢查「createPersistentCookie」?

回答

2

我相信,當你解密cookie時,你應該留下一個FormsAuthenticationTicket,然後你可以查詢IsPersistent屬性。

要解密:

FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value); 

參考文獻: FormsAuthentication.Decrypt() on MSDN

+0

正是我所需要的,謝謝! – Darryl 2013-04-07 13:38:39

相關問題