Session Expire when leaving page

Posted on 2006-03-25
Last Modified: 2008-03-10
I there a qucik way to expire a session if the user leaves the page, even if they come back before the default time out.
Question by:acaraciolo
    LVL 10

    Expert Comment

    No... but you can abandon the session which will recreate a nwe session. Thus will help if you are maintaining user state in session objects.


    However i wonder where exactly you will call this code. Need more info on what exactly you define "user laves the page"


    Author Comment

    The page displays a database of information.  The user can select criteria to limit the number of records (a certain manager, a specific date, period, etc) or the user can sort on any of the columns.  Whenever the user does this submits a selection or sorts a column the data is resubmitted.  The session variable allows me to sort the data without resubmitting the selectables i.e. if a user selects manager A the page resubmits with only manager A's information.  If the user then sorts by week ending date the Session variable insures that it doesn't reubmit the entire database.  
    I guess what I'm asking is if the user say is viewing manager 'A' for wkEndDate #3/18/2006#, then for whatever reason goes to (Lord please tell me no such place exsits) or or whatever...  and returns to the database page I want the view to be the default (All records) even if he returns before the timeout value????  If that makes sence.
    LVL 10

    Expert Comment

    for this you should maintain the state in hidden varialbes instead of sessions....

    hidden variablkes are

    <input type="hidden" value="Name" name="Sort">
    <input type="hidden" value="20" name="Week">

    maintain in these hidden elements and make sure you always store the current selected value in them and havethis within the forms opening and closing tags i.e. <form> </form>

    This way when the users comes back then these hidden fields will be blank and thus you can apply the default settings.


    Author Comment

    yes but then I'd have to rewrite the sort and selection codes otherwise everytime the form submits or the user hits refresh those values would be blank
    LVL 10

    Accepted Solution

    no they won't .... you have to assign the values ..

    for e.g.

    Dim strSort

    strSort = Requesst.Form ("sort")


    <form ... >
    <input type=hidden value="<%=strSort%>">

    Now using above code your selections will be retained across searches ... and will reset to default when the user comes back to your search page from another site.

    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 decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    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…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    754 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

    17 Experts available now in Live!

    Get 1:1 Help Now