FormsAuthentication: UserData is lost (but in Cookie)

  • Asp.Net MVC 3
  • FormsAuthentication (custom)
  • iPad MobileSafari
  • iframe (same domain)

After struggling with formsTicket.UserData without working with MobileSafari ( MoblieSafari ONLY), I found out that httpContext.User.Identity.Ticket.UserData empty (in MobileSafari and not in others) and the original HttpCookie form contains the correct values ?!?

How can it be?!

code:

 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! ... } } 

Any hint would be helpful!

Lg
Warappa

PS: If it matters, I use the page of my site in an iframe - in the same domain.

+2
source share
1 answer

So the problem was this:
This error occurred when I registered and looked at the page that had history.back() .

Looking at traffic with Fiddler, I saw that Asp.Net was using cookieless validation mode. , so authentication has been encoded in URL >. Now that history.back() occurred, the url is pointing to a Logout url with the current invalid authentication information ... an unpleasant error on my side.

Forcing Asp.Net to use cookies did the trick!

Lg
warappa

+2
source

Source: https://habr.com/ru/post/1443363/


All Articles