Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6106477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:05:01+00:00 2026-05-23T14:05:01+00:00

I want to store some data like the user nickname and user ID (table

  • 0

I want to store some data like the user nickname and user ID (table primary key) in the user data section of the auth cookie. The reason I’m doing this is to retain this data when the browser is closed, without having the user relogin.

Edit: Whoops! Realized I’d not explained myself well. I am not trying to reauthenticate a user based on their cookie. The user is already authenticated by ASP.Net’s membership system – this part is fine. My problem is that if I want to show the user’s nickname, for example, I have to fire off another SQL query, and then store it in the session. I figured it would make sense to store this information in the auth cookie (again, the one already created by ASP.Net) in the UserData section, which seems to have been created for this purpose.

I don’t want to use profiles because I have my own user table with profile data, and I needed a lightweight solution.

What is a good way to encode this data in the user data section of the auth cookie? I was thinking serialization, but that might be overkill. Am I going about this the wrong way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:05:01+00:00Added an answer on May 23, 2026 at 2:05 pm

    I’ve written an in depth tutorial on how to do this here:

    http://www.danharman.net/2011/07/07/storing-custom-data-in-forms-authentication-tickets/

    This maintains the encryption and authentication, and uses json to serialize a class into the UserData field.

    Edit:

    The blog no longer exists, an archive can be found on the web archive here.

    Summary from blog:

    Get the existing cookie and auth ticket

    HttpResponse response = HttpContext.Current.Response;
    bool rememberMe = true;
    var cookie = FormsAuthentication.GetAuthCookie(name, rememberMe);
    var ticket = FormsAuthentication.Decrypt(cookie.Value);
    

    Define your custom data (make sure this is serializable to json)

    var userData = new YourUserClass(...);
    

    Create a new auth ticket with your data, and existing auth ticket settings

    var newTicket = new FormsAuthenticationTicket(ticket.Version, 
        ticket.Name, 
        ticket.IssueDate, 
        ticket.Expiration, 
        ticket.IsPersistent, 
        userData.ToJson(), //This is where you'd set your user data
        ticket.CookiePath);
    var encTicket = FormsAuthentication.Encrypt(newTicket);
    

    Set your customized ticket into cookie and add to response

    cookie.Value = encTicket;
    response.Cookies.Add(cookie);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to temporary store some mapping data. The mapping is one to one.
I have some data that I want to store somewhere in my Rails app
I want to store the average values of some data that is occasionally generated
My C++ application stores some common user data in %CSIDL_COMMON_APPDATA%\Company\Product . I want to
I would like to store some Application-Related Metadata for Files, and NTFS Alternate Data
I want my application (PHP, but that shouldn't matter) to store some data in
i want to store and retrieve data via the url hash. the user is
I have some data stored as ArrayList . And when I want to backup
I want to generate some XML in a stored procedure based on data in
I want to use session object in my web app.I want to store some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.