[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3166
  • Last Modified:

How to end session after closing the window?

Hi,

How can I end ASP session (programmatically) after I close browser?

Please help.
0
JanWale
Asked:
JanWale
2 Solutions
 
prsupriyaCommented:
Hello....

I don't think you can kill session when the broswer closes, since sessions expire automatically after a period of time that is set in your server.

One alternative is try to use cookies combination since they stay in client side.

Other Alternative is  you can write <body unload="javascript:window.open('logout.asp')"> but I don't think it's very reliable/cross browser compatible.

in logout.asp:

//kill session
Session.Abandon

<script>
self.close();
</script>

S:
0
 
iscodeCommented:
I think you can do something like this

<SCRIPT language="JavaScript">
<!--
function loadOut()
{
window.location="http://www.yoursite.com/loadout.asp?sid=235346317";
}
//-->
</SCRIPT>

<body onBeforeUnload="loadOut()">
0
 
masirofCommented:
Session object is automatically destroyed after window closed.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
JanWaleAuthor Commented:
>Session object is automatically destroyed after window closed.

So why when I close the window and reopen new one my application took me to user that I logged-in in the first time?!
0
 
Faheem ShaikhCommented:
This might help you::The code below might give you some hints.

Create a new file global.asa containing following code::

<SCRIPT LANGUAGE='VBScript' RUNAT='Server'>
 
'You can add special event handlers in this file that will get run automatically when  
'special Active Server Pages events occur. To create these handlers, just create a
'subroutine with a name from the list below that corresponds to the event you want to
'use. For example, to create an event handler for Session_OnStart, you would put the
'following code into this file (without the comments):
 
'Sub Session_OnStart
'**Put your code here **
'End Sub
 
'EventName              Description
'Session_OnStart        Runs the first time a user runs any page in your application
'Session_OnEnd          Runs when a user's session times out or quits your application
'Application_OnStart    Runs once when the first page of your application is run for the first time by any user
'Application_OnEnd      Runs once when the web server shuts down

Sub Session_OnStart
' Create a FileSystemObject to provide files in the script
      Set Session("FSO") = CreateObject("Scripting.FileSystemObject")
      
      ' Create a variable that has the number of files created in this session
      Session("n") = 0
            Session("allowed") = false
End Sub

Sub Session_OnEnd
      Dim x
      For x = 0 to Session("n")-1
            Session("FSO").DeleteFile Session("sTempFile" & x), True
      Next
      Session("allowed") = false
End Sub


</SCRIPT>

0
 
masirofCommented:
It is impossible, if you use only Session object, not Cookie, it takes you to logged in page.
Maybe it's cache or something.
Please double check. I can assure you that when browser closed, session object terminated.
Unless of course, if you logged in another window and continue from there again.
When new window opened, that browser will act as "logged-off" not depending of your "logged-in" browser closed or not.

Please, provide process of you authentication method and check cookie. If cookie is set, it will not expire till expire time.

Ask for more if unsure.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now