kill/distroy a session

Posted on 2005-05-13
Last Modified: 2008-03-03

I currently set my sessions to nothing when the user clicks on logout in a webform.  does this completely remove it from the servers memory, or do i have to use another method to completely get rid of the session from the server?

Question by:narmi2
    LVL 7

    Assisted Solution

    i think it just marks it for deleting but the Garbage Collector comes around when it does and then removes it from memory.

    You might wanna try, after setting your session to null, something like the following:


    to tell the Garbage disposal to remove stuff from memory.

    LVL 5

    Assisted Solution


    You can use Session.Remove("Name") or Session.RemoveAll to remove your session values.

    LVL 23

    Expert Comment

    Garbage Collection is non-deterministic. This means that even by calling the GC.Collect() there is no guarantee that the objects would be removed immediately
    LVL 7

    Assisted Solution

    LVL 1

    Author Comment

    Can you please tell me the difference between:


    Also if I have 10 webforms, and in form1 I set the Session.TimeOut to 60, does this means that all other Sessions created in any of the other forms will also have a TimeOut value of 60, or will only the sessions in form1 have a timeout value of 60?

    And finally how does it know when a session is expired?  Is it possible to display the remaining session time in a textbox which updates to a lower value when the screen is refreshed?

    LVL 23

    Accepted Solution

    Session.Remove("name") removes the specific item from the Session Collection.

    Session.Abandon() destroys the current session and a new one is created. When a session expires and the client makes a HTTP Get or HTTP Post request to the web server, a new session will be created.

    Typically, sites that have user credentials used, check for say the Item "UserId" in the Session and if it is not found, we know that the user needs to be authenticated.

    The session has what you call a sliding expiry value (something that is also possible in the Cache object). Whenever the server is contacted, if the session has not expired, its timer will be reset to zero (so to speak). So when we say the session is by default 20 minutes. It means that the session will be released/cleared if the user has not contacted the server for more than 20 minutes. This effectively means trying to monitor Session times is difficult, because even though the user may be busy doing stuff on his browser, if that is all client-side, the session is ironically still aging on the server.

    So lets say a user receives a big page. Then he starts to interact with the page but this interactionm involves only client-side script. If on the 21st minute, he decides to click on the save button which does a postback, the session would have already expired on the server. But to the user, he has not been idle. To the server, that session however had aged beyond its allotted time period.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    760 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

    7 Experts available now in Live!

    Get 1:1 Help Now