Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Session?

Session?

Scheduled Pinned Locked Moved ASP.NET
databasehelpquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Karthick_gc
    wrote on last edited by
    #1

    Hi, If I close the browser window, session_end doesn't get fired. I want to do some updations in database when the user tries to close the window wiithout cliking on 'Logout' button provided. Any solution for this problem?

    A 1 Reply Last reply
    0
    • K Karthick_gc

      Hi, If I close the browser window, session_end doesn't get fired. I want to do some updations in database when the user tries to close the window wiithout cliking on 'Logout' button provided. Any solution for this problem?

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      If you close the browser, the session end will automatically called when it reached to the time out. if you want to explicitly doing something on browser close, just detect the browser close during using javascript and open some small popup which will clear the database data from server side code then close the popup also. if you find the code project asp.net forum you will find lots of similar question and answer.

      cheers, Abhijit CodeProject MVP

      K 1 Reply Last reply
      0
      • A Abhijit Jana

        If you close the browser, the session end will automatically called when it reached to the time out. if you want to explicitly doing something on browser close, just detect the browser close during using javascript and open some small popup which will clear the database data from server side code then close the popup also. if you find the code project asp.net forum you will find lots of similar question and answer.

        cheers, Abhijit CodeProject MVP

        K Offline
        K Offline
        Karthick_gc
        wrote on last edited by
        #3

        Thank u. Can u give some links to refer for the solution?

        S A 2 Replies Last reply
        0
        • K Karthick_gc

          Thank u. Can u give some links to refer for the solution?

          S Offline
          S Offline
          Sandeep Akhare
          wrote on last edited by
          #4

          Its not good to get client events by using the javascript. Another way is to write the code in the Session_End event similar event is there (I forgot :doh: ) there you can have you logic what you want to do whenever user session has been end. One question 1. Do you need to do update the DB no sooner user closed the window ?

          Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog

          A 1 Reply Last reply
          0
          • S Sandeep Akhare

            Its not good to get client events by using the javascript. Another way is to write the code in the Session_End event similar event is there (I forgot :doh: ) there you can have you logic what you want to do whenever user session has been end. One question 1. Do you need to do update the DB no sooner user closed the window ?

            Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog

            A Offline
            A Offline
            Abhijit Jana
            wrote on last edited by
            #5

            Sandeep Akhare wrote:

            Its not good to get client events by using the javascript.

            Then how will you trap the browser close event ? if you want to detect browser close you have to use javascript.

            Sandeep Akhare wrote:

            Another way is to write the code in the Session_End event similar event is there (I forgot D'Oh! ) there you can have you logic what you want to do whenever user session has been end.

            if you use Session.Abandon(), it will directly moved to Session_End() event in your Global.asax file, and inside that methods you can write your logic that what ever you want to implement.

            Sandeep Akhare wrote:

            One question 1. Do you need to do update the DB no sooner user closed the window ?

            As per my understanding, he is storing some user information while user log into the system. and he is removing those in the log off. But, the problem happens when user close the browser. If user close the browser, Session_end() will only call when its time out.

            cheers, Abhijit CodeProject MVP

            S 1 Reply Last reply
            0
            • K Karthick_gc

              Thank u. Can u give some links to refer for the solution?

              A Offline
              A Offline
              Abhijit Jana
              wrote on last edited by
              #6

              Karthick_gc wrote:

              Thank u. Can u give some links to refer for the solution?

              You can try this one,

              function DeleteUserLog()
              {

              , Alt+F4 , File -> Close

              if(window.event.clientX < 0 && window.event.clientY <0)
              {
              window.open("CloseSession.aspx", "OpenWindow_Close_Session",'left=12000,top=1200,width=10,height=1');
              }
              }

              Call this method on unload of your master Body .

              onunload="DeleteUserLog()"

              Now in CloseSession.aspx pages, you can do what ever you want and register the client script to close it automatically after doing the task. Hope this will helps you. :) BTW : I am planning for writing an article on same. Hope this will be published soon. ;) Cheers!!

              cheers, Abhijit CodeProject MVP

              1 Reply Last reply
              0
              • A Abhijit Jana

                Sandeep Akhare wrote:

                Its not good to get client events by using the javascript.

                Then how will you trap the browser close event ? if you want to detect browser close you have to use javascript.

                Sandeep Akhare wrote:

                Another way is to write the code in the Session_End event similar event is there (I forgot D'Oh! ) there you can have you logic what you want to do whenever user session has been end.

                if you use Session.Abandon(), it will directly moved to Session_End() event in your Global.asax file, and inside that methods you can write your logic that what ever you want to implement.

                Sandeep Akhare wrote:

                One question 1. Do you need to do update the DB no sooner user closed the window ?

                As per my understanding, he is storing some user information while user log into the system. and he is removing those in the log off. But, the problem happens when user close the browser. If user close the browser, Session_end() will only call when its time out.

                cheers, Abhijit CodeProject MVP

                S Offline
                S Offline
                Sandeep Akhare
                wrote on last edited by
                #7

                Abhijit Jana wrote:

                As per my understanding, he is storing some user information while user log into the system. and he is removing those in the log off. But, the problem happens when user close the browser. If user close the browser, Session_end() will only call when its time out.

                That should fine and this make sure that every time Session_End gets called 1. Please tell me what happens when system crashed or browser crashed for a perticular user... 2. depending on the client browser is not idle way as there can be many scenario there javascript may get failed. that's why i asked him is it necessary to update the DB no sonner user closed the browser? I think log information he can update when session_end gets called?

                Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups