Solved

Session_OnEnd is not working in Global.asa

Posted on 2001-06-09
7
785 Views
Last Modified: 2012-05-04
Here is my Global.asa :
<script language="vbscript" runat="server">
sub Session_OnStart
  Response.Write("It is Beginning !")
end sub

sub Session_OnEnd
  Response.Redirect("http://www.yahoo.com")
end sub
</script>


Here is my t.asp page :
<%
Session.Timeout=1  
Session("name")="ABC"
Session("age")=25
%>        


Here is my w.asp page :
<%Response.Write(Session.SessionId)%><br>
<%Response.Write(Session("name"))%><br>
<%Response.Write(Session("age"))%><br>


Here is my problem :

To initialize the whole thing, I ran t.asp first to setup
some session values. And I saw "It is Beginning !", which
Session_onStart was executed.

Then, I loaded w.asp, I saw the correct output. But after
one minute, I saw this after reload the page :

   It is Beginning !214406750

Why ? If my Session_OnEnd is not working, shouldn't I only see 214406750. Why my Session_onEnd is not working ?


0
Comment
Question by:j_script
  • 3
  • 2
  • 2
7 Comments
 
LVL 5

Expert Comment

by:dgorin
ID: 6171749
I don't think you can use response.redirect like that in Session.OnEnd.  The response object isn't available in Session.OnEnd.  The onend event fires when the session times out or is explicitly abandoned by code, so there really isn't a browser to talk to at that time.  The browser may have been closed minutes before the OnEnd event.

I imagine the OnEnd event is firing, just not able to do what you want.
0
 
LVL 9

Expert Comment

by:TTom
ID: 6172302
dgorin is right.  Redirect can't be used in session_onend since there may be no connection with the browser at that point.

I think what may be happening is that your session is timing out, but, when you reload, a new session is being created.  Therefore, you get the session_onstart value (It is beginning !) and the session ID, which you specify to be written in w.asp.  You do not get the name and age, since they are specified in t.asp (for the previous session).

If you output your sessionID in t.asp, I think you will see what is going on.

Output ID in t.asp and then run t.asp and w.asp and reload either one after a minute.  See what happens.

Tom
0
 

Author Comment

by:j_script
ID: 6172492
Then, What can I do in OnEnd session ?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:dgorin
ID: 6172573
Often session.onend is used to lower a counter of active users, clean out a database entry, etc.

What did you want session.onend to do?
0
 

Author Comment

by:j_script
ID: 6173446
I don't have any idea myself. Basically, I just want to try some features of the ASP.
Then, in this case, can I have ASP code in Global.asa ?
0
 
LVL 5

Accepted Solution

by:
dgorin earned 20 total points
ID: 6173487
0
 
LVL 9

Expert Comment

by:TTom
ID: 6173856
I have successfully used code in global.asa which queries and extracts values from database tables and a variety of other scripting code.  Code in the global.asa is pretty much like other scripts.  You just need to be very aware of when it will be executed, what it does, and what effect it can have on your users.  (For instance, code in the Application_OnStart block in the global.asa will ONLY be executed in restricted circumstances, such as when the server is restarted.  Code in a Session_OnStart block is executed each time a new user requests their first page from your server.)

Tom
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now