Cookies Value RRS feed

  • Question

  • User-797751191 posted


      I have below code , Can i get value of LoginId,Id on another page if value is not null

    FormsAuthenticationTicket tkt = new FormsAuthenticationTicket(1, LoginId.ToString(), DateTime.Now, DateTime.Now.AddMinutes(15), false, Id.ToString(), FormsAuthentication.FormsCookiePath);
                    string st = FormsAuthentication.Encrypt(tkt);
                    HttpCookie ck = new HttpCookie(FormsAuthentication.FormsCookieName, st);


    Sunday, July 21, 2019 2:30 PM

All replies

  • User-1174608757 posted

    Hi jsshivalik,

    According to your description,if you want to get LoginId value in the other page.You only need to decrypt the FormsAuthenticationTicket,then use object name to get value of LoginId and object  data  to get the value of id.

    Here is the code to decrypt and get value ,I hope it could help you.

    var authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
                if (authCookie == null) return;
                var cookieValue = authCookie.Value;
                if (String.IsNullOrWhiteSpace(cookieValue)) return;
                var ticket = FormsAuthentication.Decrypt(cookieValue);
                string name = ticket.Name;
                string data = ticket.UserData;

    Best Regards


    Monday, July 22, 2019 8:11 AM