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 8669511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:29:30+00:00 2026-06-12T18:29:30+00:00

Yet another problem with forms authentication ticket expiring too soon. I need to use

  • 0

Yet another problem with forms authentication ticket expiring too soon.
I need to use sliding Expiration set to true. I have read forums and understood the problem with the loss of precision, that the ticket only gets updated if the request is made after half of the expiration time only.

The problem:
In my webconfig I have as follows:

    <authentication mode="Forms">
        <forms timeout="20" name="SqlAuthCookie" protection="All" slidingExpiration="true" />
    </authentication>
    <sessionState timeout="20" />
    <authorization>

The user must only be logged out and redirected to login.aspx, only when there was no request made in the 20 Minute interval. The problem is that users are making requests, and still get thrown to the login page. This should not happen. What I thought of doing, was to reset the SqlAuthCookie manually for each request.

Below is my code. It is called on context.AcquireRequestState.

    void context_AcquireRequestState(object sender, EventArgs e)
    {
        HttpContext ctx = HttpContext.Current;
        ResetAuthCookie(ctx);
     }

            private void ResetAuthCookie(HttpContext ctx)
    {
        HttpCookie authCookie = ctx.Request.Cookies[FormsAuthentication.FormsCookieName];
        if (authCookie == null)
            return;

        FormsAuthenticationTicket ticketOld = FormsAuthentication.Decrypt(authCookie.Value);
        if (ticketOld == null)
            return;

        if (ticketOld.Expired)
            return;

        FormsAuthenticationTicket ticketNew = null;
        if (FormsAuthentication.SlidingExpiration)
           ticketNew = FormsAuthentication.RenewTicketIfOld(ticketOld);

        if (ticketNew != ticketOld)
            StoreNewCookie(ticketNew, authCookie, ctx);
    }

    private void StoreNewCookie(FormsAuthenticationTicket ticketNew, HttpCookie authCookie, HttpContext ctx)
    {
        string hash = FormsAuthentication.Encrypt(ticketNew);
        if (ticketNew.IsPersistent)
            authCookie.Expires = ticketNew.Expiration;

        authCookie.Value = hash;
        authCookie.HttpOnly = true;

        ctx.Response.Cookies.Add(authCookie);
    }

My questions are:

  1. Is it wrong or an acceptable solution, resetting the cookie on each request?
  2. Why does it still not work? It seems that new Ticket never gets renewed.
  3. Are there other causes possible, for the fact that the users have their forms authentication expired too soon, that I should investigate?

Thank you,
Regards,

  • 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-06-12T18:29:31+00:00Added an answer on June 12, 2026 at 6:29 pm

    A forms authentication cookie only renews itself after half it’s expiration time has passed.

    From Microsoft:

    If the Web page is accessed before half of the expiration time passes,
    the ticket expiration time will not be reset. For example, if any Web
    page is accessed again at 5:04 00:00:00 PM, the cookies and ticket
    timeout period will not be reset.

    To prevent compromised performance, and to avoid multiple browser
    warnings for users that have cookie warnings turned on, the cookie is
    updated when more than half the specified time has elapsed.

    This may be your issue. If your clients access your site at the 9 minute mark and don’t access it again for 10 minutes they’ll be timed out. This occurs even though you have your session timeout set to 20 minutes.

    Manually renewing your ticket like you’re doing isn’t necessary. You just need sliding expiration enabled. If the ‘half the specific time’ rule doesn’t work for you then you’ll have to look at other solutions.

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

Sidebar

Related Questions

I've got yet another deployment problem. What I have: little Windows Forms application that
After getting a helpful answer here , I have run into yet another problem:
I have yet another problem regarding GifImage.pas that is included with Delphi XE. The
So I have yet another problem, I am trying to get an AJAX script
Yet another data structure doubt. I will get straight to it. This is what
Yet another PHP question. I've got two arrays: one string-based and the other numeric.
Yet another newbie with ASP.NET MVC! All I intend to do is for a
I've just added yet another 3rd-party component to my .net project that contains a
I was handling yet another KeyDown event in a user control when I wondered
I have yet another issue which the answer is eluding me. I wish to

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.