sas

Topic: ASP


ASP Session Object
The Session object is used to store information about, or change settings for a user session. Variables stored in the Session object hold information about one single user, and are available to all pages in one application.

Session data is greatly misunderstood. Sessions themselves were a subtle and complex issue, but the subject was confused considerably by bad information people gathered from code others made that misused sessions. It is also confused by anecdotal performance evidence when a site is small, or the testing is only done within simple stress tests that don't reveal all the speed issues. We will clarify it all now.
<%
Session("username")="Donald Duck"
Session("age")=50
%>




Application Object
The application object works similarly to a session object in the sense that you can store variables in it and access it from any page, but it differs in the fact that all users share one application object. So, if one user runs an asp file that changes the value of something of application scope, any future access of it by that user or any other will return the new value. This also means that since the application object isn't related to any specific user session, it doesn't have any of the associated problems that session objects do. This makes it a little easier to use and, while you always need to be careful, you're much less likely to bring a server to it's knees using the application object then you are using the session object.
Event
Application_OnEnd
Application_OnStart

The following example uses the application variable NumVisits to store the number of times that a particular page has been accessed. The Lock method is called to ensure that only the current client can access or alter NumVisits . Calling the Unlock method then enables other users to access the Application object.
<%
Application.Lock Application("NumVisits") = Application("NumVisits") + 1 Application.Unlock
%>

This application page has been visited
<%= Application("NumVisits") %> times!

Prev