Session duration in ASP.NET

Posted on 2006-05-02
Last Modified: 2007-12-19
Hi Experts,

1) By default the session duration is 20min, if the user exceeds the time, i want to keep live that session. how?
2) how can we know that user is active or he is idle?
3) How can we extend teh session duration if user is active?

with regards
Question by:gbreddy
    LVL 15

    Assisted Solution

    You might want to read up about Sessions.

    1. You can set the timeout explicitly in the web.config or in your code
    2. You can't, since the web is stateless you know the user is active when they do a postback.
    3. The session will extend itself. 20 minutes from the last postback received.

    LVL 23

    Expert Comment

    This AJAX solution may help you in keeping your session alive
    LVL 2

    Accepted Solution

    I agree with 1 and 3.

    For the second one you can check the IsClientConnected property to check the user connectivity. It is good to use this property in long processes such as sending a file to client.


    If Response.IsClientConnected=true then
    Response.Write("The user is still connected!")
    Response.Write("The user is not connected!")
    end if

    LVL 3

    Assisted Solution

    Like everyone said, you dont really know if a user left your page or left his browser open to the page or turned the browser off, only that he was active in the last somany minutes.

    of course you could include some code in anyscreen that kept the session active via some mechanism... ajax or even a hidden frame or iframe with a single line that did a meta refresh every minute or so. (make sure its a .aspx page not a html page, that wont keep the session alive)

    You can persist the user data forever if you want by changing the session state to be stored in a DB instead of in memory.
    webconfig stuff...
    <sessionState   mode="SQLServer"  sqlConnectionString="data source=server;user id=uid;password=pwd"  />
    .net has the tools to create the sql db.
    LVL 15

    Expert Comment

    Split 4 ways. Everyone gave a possible solution

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    761 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

    12 Experts available now in Live!

    Get 1:1 Help Now