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

  • Home
  • SEARCH
  • 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 118279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:28:10+00:00 2026-05-11T03:28:10+00:00

I have an asp.net website that uses forms authentication. There are a few things

  • 0

I have an asp.net website that uses forms authentication. There are a few things I keep in sessions like username, userID, email, etc.

I allow the user to stay logged into the website by setting a long expiration date on the authentication cookie. So it’s very common for the session to expire while the user is still authenticated.

The problem I am running into is that sometimes the user’s session times out but they’re still authenticated. So for example, one of my user pages (which requires authentication) will say ‘Welcome Mike’ when their session is active but once it expires it will say ‘Welcome [blank]’ because the info is no longer in the session, yet they are still authenticated.

What’s the best way to handle this? Should I resync the session info when the info is no longer there? Or should I move the user info (username, userID, email) into cookies and not worry about session timeouts?

I do not want to set the session length to something like 60 minutes or more. What i want is for my users to be able to login once and not worry about having to login again until they explicitly logout.

  • 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. 2026-05-11T03:28:11+00:00Added an answer on May 11, 2026 at 3:28 am

    Avoid using session as much as you can, if you can get away without seesion it makes multi-server deployments qutie a bit easier. Probably, Name and email are easy candidates for cookies. It’s easy to fake a cookie, so userID may not be a good idea depending on your security needs.

    The forms authentication cookies are encrypted and you can add extra data to those cookies (See details below). It’s probably hackable but not nearly as easily as a simple cookie.

    Here is the code I have used in the past slightly modified to remove some project specific details. Call this in the LoggedIn event of the login control.

    void AddUserIDToAuthCookie(string userID)   {     //There is no way to directly set the userdata portion of a FormAuthenticationTicket     //without re-writing the login portion of the Login control     //     //I find it easier to pull the cookie that the Login control inserted out     //and create a new cookie with the userdata set      HttpCookie authCookie = Response.Cookies[AUTH_COOKIE];   if(authCookie == null)   {     return;   }    Response.Cookies.Remove(AUTH_COOKIE);    FormsAuthenticationTicket oldTicket = FormsAuthentication.Decrypt(authCookie.Value);   var newTicket =     new FormsAuthenticationTicket(oldTicket.Version, oldTicket.Name, oldTicket.IssueDate, oldTicket.Expiration,                                   oldTicket.IsPersistent, userID, oldTicket.CookiePath);    authCookie.Value = FormsAuthentication.Encrypt(newTicket);    Response.Cookies.Add(authCookie); } 

    FYI, I copied this from an old project and edited it here to remove some project specific bits, so it may not compile, but it’ll be very close.

    To get the ID in your webpage…

    FormsAuthenticationTicket ticket = ((FormsIdentity) Page.User.Identity).Ticket; string id = ticket.UserData; 

    I used this mechanism to store an id that was not part of the aspnetdb user data. If all your identity data is handled by the aspnetdb, you may only need to access the Page.User.Identity object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 64k
  • Answers 64k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I think a direct insertion with a progressive (and slow)… May 11, 2026 at 10:58 am
  • added an answer Well you could do a : Form.ShowDialog() This will prevent… May 11, 2026 at 10:58 am
  • added an answer Both CAutoPtr and auto_ptr give you smart pointer semantics including… May 11, 2026 at 10:58 am

Related Questions

I have an asp.net website that uses forms authentication. There are a few things
I have an asp.net website that allows the user to download largish files -
I have an ASP.NET website (in C#) that takes in user data and then
I have an ASP.NET MVC (Beta 1) website that I'm using themes with. When
I have an asp.net mvc app running on a local iis website that is
I currently have an asp.net website hosted on two web servers that sit behind
I have a webservice that exists in an asp.net website. When I publish the
I have an ASP.NET website and when I press F5 it automatically attaches to
I have an ASP.net website ( http://www.erate.co.za ) version 2.0. When someone opens my
I have an ASP.Net hosted website which displays a list of results as a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.