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. how to remove session when browser closed.

how to remove session when browser closed.

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
4 Posts 2 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.
  • U Offline
    U Offline
    uspatel
    wrote on last edited by
    #1

    Is it possible,To remove session when user close his browser. if yes , how?

    J 1 Reply Last reply
    0
    • U uspatel

      Is it possible,To remove session when user close his browser. if yes , how?

      J Offline
      J Offline
      Jitendra Parida Jeetu
      wrote on last edited by
      #2

      Hi, Try this one: http://stackoverflow.com/questions/3102241/authentication-session-cookie-deleting-after-browser-close[^]

      U 1 Reply Last reply
      0
      • J Jitendra Parida Jeetu

        Hi, Try this one: http://stackoverflow.com/questions/3102241/authentication-session-cookie-deleting-after-browser-close[^]

        U Offline
        U Offline
        uspatel
        wrote on last edited by
        #3

        It is for restoring Session not for deleting.

        J 1 Reply Last reply
        0
        • U uspatel

          It is for restoring Session not for deleting.

          J Offline
          J Offline
          Jitendra Parida Jeetu
          wrote on last edited by
          #4

          try this: 1. First create a page LogOut.aspx and in Page_Load event write this code:-

          protected void Page_Load(object sender, EventArgs e)
          {
          Session.Abandon();
          }

          2. Then add following JavaScript code in your page or Master Page:-

          <script type="text/javascript">

          var clicked = false;
          

          function CheckBrowser()
          {
          if (clicked == false)
          {
          //Browser closed
          }
          else
          {
          //redirected
          clicked = false;
          }
          }

          function bodyUnload()
          {
              if (clicked == false)//browser is closed
              {
              var request = GetRequest();
                 
              request.open  ("GET", "AutoLogOut.aspx", true);
              request.send();
              }
          }
          
          function GetRequest()
          {
              var request = null;
              if (window.XMLHttpRequest)
              {
                  //incase of IE7,FF, Opera and Safari browser
                  request = new XMLHttpRequest();
              }
              else
              {
                  //for old browser like IE 6.x and IE 5.x
                  request = new ActiveXObject('MSXML2.XMLHTTP.3.0');
              }
              return request;
          } 
          

          **3. Add the following code in the body tag of master page.

          <body onunload="bodyUnload();" Onclick="clicked=true;">

          Finally the code in Master page like this:-

          //<!\[CDATA\[
          
          var clicked = false;
          function CheckBrowser() {
              if (clicked == false) {
                  //Browser closed
              }
              else {
                  //redirected 
                  clicked = false;
              }
          }
          
          function bodyUnload() {
              if (clicked == false)//browser is closed
              {
                  //var request = GetRequest();
                 
                  //location.href = 'LogOut.aspx';
                  var request = GetRequest();
          
                  request.open("GET", "LogOut.aspx", true);
                  request.send();
              }
          }
          function GetRequest() {
              var request = null;
              if (window.XMLHttpRequest) {
                  //incase of IE7,FF, Opera and Safari browser
                  request = new XMLHttpRequest();
              }
              else {
                  //for old browser like IE 6.x and IE 5.x
                  request = new ActiveXObject('MSXML2.XMLHTTP.3.0');
              }
              return request;
          } 
          

          </x-turndown>

          **

          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