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. Clear Session While Browser Close

Clear Session While Browser Close

Scheduled Pinned Locked Moved ASP.NET
tutorial
6 Posts 5 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi All, How to clear session when i close the browser. I have assigned the following value in session Session["SessionId"] = sessionId; Session["userId"] = userId; I want to clear this value while user close Browser Thanks and regards, Amit Patel

    A B Z C 4 Replies Last reply
    0
    • L Lost User

      Hi All, How to clear session when i close the browser. I have assigned the following value in session Session["SessionId"] = sessionId; Session["userId"] = userId; I want to clear this value while user close Browser Thanks and regards, Amit Patel

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Why do you require an extra server call to clear session.. Rather you can use Session Timeout easily which is automatically called.

      Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


      My Latest Articles-->** Windows7 API Code Pack
      Simplify Code Using NDepend
      Basics of Bing Search API using .NET

      L 1 Reply Last reply
      0
      • L Lost User

        Hi All, How to clear session when i close the browser. I have assigned the following value in session Session["SessionId"] = sessionId; Session["userId"] = userId; I want to clear this value while user close Browser Thanks and regards, Amit Patel

        B Offline
        B Offline
        Brij
        wrote on last edited by
        #3

        For that you have to capture the browser close event from javascript and if it is browser close then open a new page remove the session from server side of that page then close that page.I have impleneted in this way.The sample code is : Javscript code to capture the browser close event and accordingly open the new page to remove the session

        function CloseSession() {

        , 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 it'll help you. :)

        Cheers!! Brij

        1 Reply Last reply
        0
        • L Lost User

          Hi All, How to clear session when i close the browser. I have assigned the following value in session Session["SessionId"] = sessionId; Session["userId"] = userId; I want to clear this value while user close Browser Thanks and regards, Amit Patel

          Z Offline
          Z Offline
          ZHAOBING_NTU
          wrote on last edited by
          #4

          Session.clear

          1 Reply Last reply
          0
          • A Abhishek Sur

            Why do you require an extra server call to clear session.. Rather you can use Session Timeout easily which is automatically called.

            Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


            My Latest Articles-->** Windows7 API Code Pack
            Simplify Code Using NDepend
            Basics of Bing Search API using .NET

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Hi I want to implement functionality where user can login from one system only if he logs in from other machine then he should logged out from another machine so for this we implemented forced logout for this i created on dictionary in App code in global which contains user id and corrospoding session id but when i closing my browser it is not getting removed so when i m logging from same machine it is also iving forced logout is session is not expired so i dont want to show this message Thanks amit

            1 Reply Last reply
            0
            • L Lost User

              Hi All, How to clear session when i close the browser. I have assigned the following value in session Session["SessionId"] = sessionId; Session["userId"] = userId; I want to clear this value while user close Browser Thanks and regards, Amit Patel

              C Offline
              C Offline
              carlecomm
              wrote on last edited by
              #6

              add Session["user"]=user; clear Session.Remove("user");

              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