【问题标题】:How do I check the "createPersistentCookie" in ASP.NET Forms Authentication?如何检查 ASP.NET 表单身份验证中的“createPersistentCookie”?
【发布时间】:2011-05-24 16:52:22
【问题描述】:

当有人登录我的应用程序并选中“记住我”复选框时,我设置了createPersistentCookie = true,这样当他们回来时就不需要再次登录。但是,有时我需要使用FormsAuthentication.SetAuthCookie(NewUserName, [true/false]),所以我如何知道他们最初是否将createPersistentCookie 设置为true,以便我可以保持与他们登录时一样?

【问题讨论】:

    标签: asp.net forms-authentication


    【解决方案1】:

    我相信当您解密 cookie 时,您应该留下一个 FormsAuthenticationTicket,然后您可以查询 IsPersistent 属性。

    解密:

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

    参考资料: FormsAuthentication.Decrypt() on MSDN

    【讨论】:

      【解决方案2】:

      您还应该记住在应用程序的 web.config 中设置为常量值。 ASP.NET 倾向于在一段时间后自动生成此值。

      欲了解更多信息,请查看:http://msdn.microsoft.com/en-us/library/w8h3skw9(v=VS.90).aspx

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-09-28
        • 1970-01-01
        • 1970-01-01
        • 2011-03-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多