User authenticated but missing Ticket.UserData

I have the following code:

if (HttpContext.Current.Request.IsAuthenticated == false)
{
    // this isn't reached so i know user is Authenticated
    return;
}
FormsIdentity fIdentity = HttpContext.Current.User.Identity as FormsIdentity;
string[] delimitedUserData = fIdentity.Ticket.UserData.Split('|');
// but at this point delimitedUserData.Length is 0

Any ideas on what might make the authentication ticket valid but UserData is gone?

My program works fine, and all UserData are easily accessible. But every time after a while I fall into this state where UserData does not exist.

+3
source share
4 answers

The ticket is stored in a cookie. What happens in your code when you access the page immediately after the expiration of the cookie?

Also note that User.Identity.IsAuthenticatedreturns true from the field, so the property may not be the best, what can I check for?

0

FormsAuthentication UserData. , ( UserData) , .

, , . , cookie, cookie .

Firefox, " N ": https://addons.mozilla.org/en-US/firefox/addon/573

0

, , asp.net, , , - , - cookie , , .

, ( _LoggedIn) :

        // write ClientID to the session
        Session.Add("ClientID", lClientID);

:

if (User.Identity.IsAuthenticated == false || Convert.ToInt32(Session["ClientID"]) == 0)
    {
        Server.Transfer("Login.aspx");
    }

.

0

, "FormsAuthentication.RedirectFromLoginPage" cookie. "response.cookies.add". .

0

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


All Articles