ASP.NET how to extend session time?

Posted on 2011-05-07
Last Modified: 2012-05-11
user logs in.  inside their control panel, they write up a bio.  when they click "Submit", they are bounced back to the login screen because they are no longer "logged in"

I'm using this code at the top of the control panel pages:
If Session("Auth") = False Then
        End If
        Name = Session("Name")
        UserID = Session("UserID")
        Auth = Session("Auth")

So, what happens is, they are taking too long writing up their bio and are bouncing out.  How do I extend the session to 30 minutes, or even an hour?
Question by:arthurh88

    Expert Comment

    This a server-side setting. You can edit the web.config and adjust as shown below:
            <sessionState timeout="1800"/>

    Otherwise you can go into IIS Manager configure it there as well.
    LVL 11

    Accepted Solution

    Create  one page in same application name it as SessionExtender.aspx
    write below code on page load event of it

    protected void Page_Load(object sender, EventArgs e)

    Session.Timeout = (!

    string.IsNullOrEmpty(Request.QueryString["t"])) ? (Int16)Request.QueryString["t"] : 10;

    // here we are passing time to extend values in query string if it is null it will take 10 min



    Now open othe pages like home page.aspx etc where you would like to extend the session.

    in body tag call below java script function

    ExtendSession() some thing like this

    <body onload="ExtendSession();">


    In your head tag add below javascript

    function ExtendSession()()
    var img = new Image();
    img.src="SessionExtender.aspx";   // or using query string t as img.src="SessionExtender.aspx?t=5";  
    alert('called'); // make sure it is called after 3 second you can delete it. It is just for your refrence or **
    function ExtendSession()


    in web.config file find <sessionState> node:




    sqlConnectionString="data source=;user id=sa;password="




    default is 20 - change it

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now