如何检查“createPersistentCookie”在 ASP.NET 表单身份验证中?
当有人登录我的应用程序并选中“记住我”复选框时,我设置了 createPersistentCookie = true ,这样当他们回来时就不需要再次登录。但是,偶尔,我需要使用 FormsAuthentication.SetAuthCookie(NewUserName, [true/false])
那么我如何知道他们最初是否将 createPersistentCookie
设置为 true 或不是这样我就可以保持和他们登录时一样吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信当您解密 cookie 时,您应该留下一个
FormsAuthenticationTicket
,然后您可以查询IsPercient
属性。解密:
参考资料:
MSDN 上的 FormsAuthentication.Decrypt()
I believe when you decrypt the cookie you should be left with a
FormsAuthenticationTicket
which you can then query theIsPersistent
property.To decrypt:
References:
FormsAuthentication.Decrypt() on MSDN
您还应该记住在应用程序的 web.config 中设置为常量值。 ASP.NET 倾向于在一段时间后自动生成该值。
有关详细信息,请查看:http:// msdn.microsoft.com/en-us/library/w8h3skw9(v=VS.90).aspx
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