How do I check the “createPersistentCookie” in ASP.NET Forms Authentication?

荒凉一梦 提交于 2019-12-11 09:25:24

问题


When someone logs into my application and they checked the "Remember Me" checkbox, I set the createPersistentCookie = true so that when they come back they don't need to log in again. However, occassionally, I need to use the FormsAuthentication.SetAuthCookie(NewUserName, [true/false]) so how do I know if they originally set the createPersistentCookie to true or not so I can keep it the same as it was when they logged in?


回答1:


I believe when you decrypt the cookie you should be left with a FormsAuthenticationTicket which you can then query the IsPersistent property.

To decrypt:

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

References: FormsAuthentication.Decrypt() on MSDN




回答2:


You should also remember to set in your application's web.config to constant value. ASP.NET has tendency to auto generate this values after some time.

For more info please take look at: http://msdn.microsoft.com/en-us/library/w8h3skw9(v=VS.90).aspx



来源:https://stackoverflow.com/questions/6113972/how-do-i-check-the-createpersistentcookie-in-asp-net-forms-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!