clear session

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anithaapr05
    New Member
    • Aug 2009
    • 11

    clear session

    Dear All,

    I have an ASP.net page. When I am closing the webpage I need to clear the session variables.

    I need to close the session variales at time of my browser is close directly,withou t using the logout link.

    Is there any possiblity for clearing the session variable.

    Thanks
    Anitha
  • maliksleo
    New Member
    • Feb 2009
    • 115

    #2
    use the page unload event or try to use java script for that on window.close() function remove your all sessions.

    Comment

    • ssnaik84
      New Member
      • Aug 2009
      • 149

      #3
      try using AJAX with body onunload event

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        You should use the onbeforeunload javascript event.

        This event is fired just before the page is unloaded. After the onbeforeunload event (the unload event is fired) the page is unloaded JavaScript and Ajax are no longer available to you. Please look over the article I linked you to because this event is a bit special.

        After you've read that check out this solution that outlines how to clear session using the onbeforeunload event and Ajax.

        Happy coding!

        -Frinny

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Hmm, I just read through the post I linked you to and I realized that there's probably an easier way to "register" your controls on the page.

          When the page is loaded (javascript window.onload event or during the Ajax end request event) you could use JavaScript loop through all of the controls on the page and add events instead of doing this on the server.


          :)

          -Frinny

          Comment

          • ssnaik84
            New Member
            • Aug 2009
            • 149

            #6
            heyy.. that's great articles Frinny!! thanks a million.. :)

            Comment

            • ssnaik84
              New Member
              • Aug 2009
              • 149

              #7
              I would like you to take a look at http://www.irctc.co.in
              It is an official website for ticket booking by indian railway.
              it has huge database and millions of transactions held on daily basis.
              they have same functionality implemented but in different way.
              they are sending session id in URL and checking each time on page_load, i guess.
              obviously, it is not developed in asp.net, but i m just trying to point out their implementation way.
              -- swapnil

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                They're using cookieless session.

                ASP.NET has that option too...you can set it in the web.config file if you want to. It's not as secure as using a cookie because you can just copy the URL (which includes the session ID) and pass it on to some other person (who may, as a result of the session ID in the URL, be logged in as that user etc).

                It's handy in some scenarios but not in others.

                I'm glad you liked the link. I'm in the middle of converting it into an article because your question is quite commonly asked.

                Comment

                Working...