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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:33:32+00:00 2026-05-29T15:33:32+00:00

I have an AJAX method to call on server to return .ASPXAUTH cookie expiration

  • 0

I have an AJAX method to call on server to return “.ASPXAUTH” cookie expiration time.
It works properly when the auth cookie presents.

Besides I want to renew user logon session with another AJAX call. I have a blank method “RenewSession” which is just for to make a call to the server. Is there any way to do this using Forms Authentication?
The problem is in that when I make a request to server to my “RenewSession” method to renew the session Response.Cookies array is always containing 0 items. But actually when the “.ASPXAUTH” cookie expiration time gets to 0 it renews.

So can anyone explain is it a browsers’ or ASP.NET/MVCs’ behaviour?
Maybe I need sliding expiration to be set to “true”?
Or maybe in my renew method I should re-login the user and put a new cookie in the response?

Thank you!

  • 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-29T15:33:33+00:00Added an answer on May 29, 2026 at 3:33 pm

    FormsAuthentication expiration is really a matter of two parts:

    • the expiration of the authentication ticket
    • the expiration of the cookie containing the ticket

    If you want to leave sliding expiration off, and renew the ticket manually, you need to renew the ticket and return a new authentication cookie to the browser.

    The Response.Cookies array is empty unless you (or other code) add something to it. It’s only meant for adding cookies that are new or whose contents/expiration/whatever have changed. An empty Response.Cookies only means that nothing has changed – the browser will keep the cookies it already has (until they expire) and still send them on the next request.

    The standard way of modifying cookie contents or expiration is to take a cookie the browser sent (from Request.Cookies), modify it, and then add it to Response.Cookies.

    Here’s a bit of sample code for manually renewing the authentication cookie (disclamer: Test thoroughly and think):

    // You could also get the ticket from
    // Request.Cookies using FormsAuthentication.Decode
    FormsIdentity identity = HttpContext.Current.User.Identity as FormsIdentity;
    if (identity == null) return; // User isn't authenticated
    
    // Renew the ticket - you could also create a new ticket manually 
    // (see * below for an example), if you want to get rid of ASP.NET's 
    // rather confusing renew-if-old policy:
    FormsAuthenticationTicket ticket = 
       FormsAuthentication.RenewTicketIfOld(identity.Ticket);
    
    string encryptedTicket = FormsAuthentication.Encrypt(ticket);
    HttpCookie cookie = new HttpCookie(
       FormsAuthentication.FormsCookieName,
       encryptedTicket
    );
    
    // Better keep this (see * below):
    cookie.Secure = FormsAuthentication.RequireSSL;
    cookie.HttpOnly = true;
    
    // Isn't a security issue if this is set too long - the ticket contained
    // within will still expire after the set time, and the server will timeout
    // the auth session on the next request.
    // But let's just keep cookie and ticket in sync:
    cookie.Expire = ticket.Expiration;
    
    // Add cookie to response to send the changes to the browser:
    HttpContext.Current.Response.Cookies.Add(cookie);
    

    Note that FormsAuthentication.RenewTicketIfOld() won’t always renew the ticket. It will only renew if less than half of the expiration time is left. I.e., if your timeout in web.config is set to 20 minutes and RenewTicketIfOld is called 7 minutes after the ticket was created, the ticket won’t be renewed, and there’ll still be 13 minutes left. If it’s called after e.g. 12 minutes, it will be renewed to 20 minutes.

    The reason for this is because RenewTicketIfOld is used by slidingExpiration on every request and so would send back a new cookie on every request (to reset the expiration to [timeout] minutes). Only sending a new ticket cookie back when at least half the time has elapsed gets rid of a lot of cookie overhead – at the expense of being confusing to developers and end users.

    *) On cookie.Secure, see Hanselman: Weird Timeouts – this simply makes sure that if RequireSSL is set in web.config, the cookie will honor that, which avoids many a debugging nightmare if you ever move the site to SSL.

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

Sidebar

Related Questions

I have a method I want to call using AJAX in rails but I
I have a AJAX post method that gets xml data from server. But when
Lets say i have a ajax method which call a script that checks if
I have a simple web method and ajax call and continue to recieve an
I have this AJAX code, but it doesn't seem to throw the 'alert' method.
I have an MVC view with a form built with the Ajax.BeginForm() helper method,
I am simply learing Ajax with jQuery and have a simple page method that
I have ajax code for asp.net (non-mvc) to call to a webMethod to get
I'm currently using jquery ajax to call a pagemethod (which works great); $.ajax({ type:
Within a web form I have the following jQuery setup to call a method

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.