【问题标题】:FormsAuthentication: UserData lost (but in Cookie)FormsAuthentication:用户数据丢失(但在 Cookie 中)
【发布时间】:2011-05-19 14:08:16
【问题描述】:
  • Asp.Net MVC 3
  • FormsAuthentication(自定义)
  • iPad MobileSafari
  • iframe(同域)

在与 formsTicket.UserData 不兼容 MobileSafari(仅限 MoblieSafari)苦苦挣扎后,我发现 httpContext.User.Identity.Ticket.UserDataempty(在 MobileSafari 中,而不是其他)而原始的 FormsAuthentication HttpCookie 包含 正确的值?!?

怎么可能?!

代码:

public void UpdateContext()
{
    if (httpContext.User.Identity is FormsIdentity)
    {
        // Get Forms Identity From Current User
        FormsIdentity id = (FormsIdentity)httpContext.User.Identity;
        // Create a custom Principal Instance and assign to Current User (with caching)
        HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(FormsAuthentication.FormsCookieName);
        FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);

        var cookieUserData = ticket.UserData; // not empty
        var httpContextIdentiyUserData = id.Ticket.UserData; // empty!
        ...
    }
}

任何线索都会有所帮助!

Lg
瓦拉帕

PS:如果重要的话,我会在 iframe 中使用我网站的一个页面 - 同一个域。

【问题讨论】:

标签: cookies forms-authentication mobile-safari user-data


【解决方案1】:

所以问题如下:
当我退出并访问执行 history.back() 的页面时出现此错误。

用Fiddler看流量我看到,Asp.Net使用的是cookieless 认证方式,所以认证是 编码到网址中。现在,当history.back() 发生时,url 指向 Logout url 与现在 无效的身份验证信息...在我身边的讨厌的错误。

强制 Asp.Net 使用 cookie 成功了!

Lg
瓦拉帕

【讨论】:

  • 这是个老问题,但我遇到了类似的问题。你能解释一下如何强制asp.net使用cookies吗?提前谢谢你,很抱歉打扰你:))
猜你喜欢
  • 2014-09-10
  • 2011-01-14
  • 2012-12-14
  • 2013-01-23
  • 2015-01-18
  • 1970-01-01
  • 2014-11-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多