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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:24:23+00:00 2026-05-20T00:24:23+00:00

So there are lots of posts on StackOverflow regarding this, but I still was

  • 0

So there are lots of posts on StackOverflow regarding this, but I still was unable to solve my exact problem. Here’s the gist:

I have a website that requires authentication. I am using the standard .NET FormsAuthentication.SetAuthCookie() method to persist the user’s session.

My question is this: In the web.config file, there is a timeout attribute to the “/system.web/authentication/forms” node. If I set this value to say, 30 minutes, is this the time of user inactivity the user can have before their session expires?

The reason I ask is that no matter what I set this value to, if I set persistence to true in SetAuthCookie(), the expiration on the cookie set is 90 minutes. If I set persistence to false in SetAuthCookie(), the cookie expiration is set to “end of session”.

What is that “Timeout” attribute value actually setting, and how can I get a persistent cookie that lasts a month or a year or longer?

  • 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-20T00:24:24+00:00Added an answer on May 20, 2026 at 12:24 am

    The parameter timeout you’ve found in /system.web/authentication/forms is the timeout (in minutes) of the duration of authentication ticket.

    This means that after a certain amount of time of inactivity, a user is prompted to login again. If you try to check this My.Profile.Current.IsAuthenticated it will be false.

    You can choose not to persist the cookie. In this situation if your ticket expires, your cookie expires too. The cookie (in case is persisted) has a purpose to remember the user if he/she comes back to your site.

    You might want to persist your cookie for 10 years so the user will never have to insert username and password again, unless they’ve chosen to delete the cookie. The cookie is valid even if the browser is closed (when it is persisted).

    Another important thing to remember is the parameter slidingExpiration:

    <authentication mode="Forms">
        <forms loginUrl="~/Partner/LogOn" defaultUrl="~/Home/Index" 
               timeout="30" slidingExpiration="true" />
    </authentication>
    

    if it’s true your authentication ticket will be renewed every time there’s activity on your site: refresh of the page etc.

    What you can do – and what I’ve done – is to write your own cookie like this:

     FormsAuthenticationTicket authTicket = new
         FormsAuthenticationTicket(1, //version
         userName, // user name
         DateTime.Now,             //creation
         DateTime.Now.AddMinutes(30), //Expiration (you can set it to 1 month
         true,  //Persistent
         userData); // additional informations
    

    Update

    I’ve implemented this routine cause I want to store my groups in an encrypted cookie:

    Dim authTicket As System.Web.Security.FormsAuthenticationTicket = _
            New System.Web.Security.FormsAuthenticationTicket( _
                1, _
                UserName, _
                Now, _
                Now.AddYears(100), _
                createPersistentCookie, _
                UserData)
    
    Dim encryptedTicket As String = System.Web.Security.FormsAuthentication.Encrypt(authTicket)
    
    Dim authCookie As HttpCookie = New HttpCookie( _
        System.Web.Security.FormsAuthentication.FormsCookieName, _
        encryptedTicket)
    
    If (createPersistentCookie) Then
        authCookie.Expires = authTicket.Expiration
    End If
    
    Response.Cookies.Add(authCookie)
    

    As you can see I’ve set the expiration of the authentication cookie and the authentication ticket with the same timeout (only when persisted).

    Another thing that I’ve tried is to stored username and password in the encrypted cookie.
    Everytime a masterpage is loaded I check My.Profile.Current.IsAuthenticated to see if the authentication is still valid. If not I read the cookie again, get the username and password, and check it on the DB:

    Public Function ReadCookieAuthentication(ByVal Context As System.Web.HttpContext) As Security.CookieAuth
    
        Dim CookieUserData = New Security.CookieAuth()
    
        Dim cookieName As String = System.Web.Security.FormsAuthentication.FormsCookieName
        Dim authCookie As HttpCookie = Context.Request.Cookies(cookieName)
    
        If (Not (authCookie Is Nothing)) Then
            Dim authTicket As System.Web.Security.FormsAuthenticationTicket = Nothing
            Try
                authTicket = System.Web.Security.FormsAuthentication.Decrypt(authCookie.Value)
                If (Not (authTicket Is Nothing)) Then
                    If (authTicket.UserData IsNot Nothing) AndAlso Not String.IsNullOrEmpty(authTicket.UserData) Then
                        CookieUserData = New JavaScriptSerializer().Deserialize(Of Security.CookieAuth)(authTicket.UserData.ToString)
                    End If
                    CookieUserData.UserName = authTicket.Name
                End If
            Catch ex As Exception
                ' Do nothing.
            End Try
        End If
    
        Return (CookieUserData)
    
    End Function
    

    Security.CookieAuth is an object I’ve created to return username and password.
    CookieUserData is the storage (I save in json format) where I put my password and groups.

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

Sidebar

Related Questions

I have been researching this problem and while there's lots of posts on various
I know there are lots of stack overflow posts about this. I have this
Well, I know there is a lots of posts about it, but I have
I've seen lots of posts on SE relating to this, but none have answered
I have been reading through lots of Q&A everywhere and these stackoverflow posts seem
hi every1 i have been reading lots of posts here about how to use
There are lots of posts on here about moving a folder out of one
I have been reading lots of posts and am confused as to why this
I have got lots of ideas from google and stackoverflow- but none of those
Good day! I know there has been lots of posts for this kind of

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.