The session
The session is created when we open an ASP page - as said. Upon session opening, a cookie is created client-side with the session id. Something similar to:
Cookie: ASPSESSIONID=PUYQGHUMEAAJPUYL
That cookie has no expiration date, meaning that it will be flushed when the user exits the browser. At the same time, the created session will expire in 20 minutes by default - as said - if the page is not refreshed or if a new request is not made.We can change the session timeout using:
<%
Session.Timeout=5
%>
The value is expressed in minutes (5 minutes). And use the Abandon method to end the session:
<%
Session.Abandon
%>
The session object supports an array that can be used to store information.
How to store information
The way we store information in the session object is very similar to the way we do it with cookies. For example, we can store the user name and the gender:
<%
Session ("username") = "Denny Crane"
Session ("gender") = "Male"
%>
And then, display those information:
Hello <%= Session("username")%>
We know you are <%= Session("gender")%>
Simple as that! As you can see, sessions work like cookies.
Remove information
To remove the stored information, we can use the following code:
<%
Session.Contents.Remove("username")
%>
Or remove all the info:
<%
Session.Contents.RemoveAll()
%>
All the above can be used in the global.asa file on the server, to control what's happening on session start and end. I will probably write something about it in the near future.
And that is all. See you next time and have a splendid summer day!
No comments:
Post a Comment
Comments are moderated. I apologize if I don't publish comments immediately.
However, I do answer to all the comments.