j_script
asked on
Session_OnEnd is not working in Global.asa
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.S essionId)% ><br>
<%Response.Write(Session(" name"))%>< br>
<%Response.Write(Session(" age"))%><b r>
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 ?
<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.S
<%Response.Write(Session("
<%Response.Write(Session("
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 ?
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
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
ASKER
Then, What can I do in OnEnd session ?
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?
What did you want session.onend to do?
ASKER
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 ?
Then, in this case, can I have ASP code in Global.asa ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Tom
I imagine the OnEnd event is firing, just not able to do what you want.