The Session object stores information needed for a particular user's session on the web server. It is automatically created every time when an ASP page from the web site or web application is requested by a user who does not already have a session, and it remains available until the session expires.
The Session object is user specific. It can be used to store variables specific to a particular user and IIS will maintain these variables when the client moves across pages within your web site.
ASP Sessions are cookie based, it uses HTTP Cookies to send users their unique session keys. Asp application responds to the users request with an http header that consists of a unique session key(for the first time) and subsequent requests from the same browser are identified by the session key.
ASP automatically processes this cookie and uses it to restore the values saved in the Session object. The cookie that is sent by ASP as a session ID does not provide an expiration time. Cookies with no expiration specified are only valid until the browser is closed. In this way the cookie is flushed when the user exits the browser.
The Session object is based on using cookies, so if cookies are not permitted on the client browser, the Session object is rendered useless and the page stop working.
How Asp Session Works
When a user sends a web page request, In response to the request, the server creates a cookie that consists the session id for the particular user and Place it in the HTTP Header and sends it before it sends any HTML output. Even the ASP script doesn’t need any session management it sends unique session id for every request to the server from the user until a session state is created. If the session state is not created for the particular session id for the next request from the browser it will send another session id. Once the script stores some value in the session , for the next requests from the browser it uses the session id to identify the user.
We can turn off the sessions in our applications if we don’t need it by using the registry.
The AllowSessionState registry or configuration file setting controls the creation of Session objects. If AllowSessionState is set to False, the Session object cannot be used. The default is to use Sessions
ASP Session objects consists
Collections
Methods
Properties
Syntax: Session. Collections Property Method
1. Collections: Asp Session Objects Collection are
Contents: contains Items that have been created for Session. Contents can be used to get a value of item, to iterate through all the items, to remove items. Remove method of the collection helps to remove the item from the collection. To remove all the items we use Removeall method
Session.Contents.Count gives number of items in the collection
To remove item from the sessions collection .let us suppose “Age” in our example
Session.Contents.Remove(“age”)
To remove all session items .
Session.Contents.Removeall()
Static Objects : contains items created in global.asa file with
2. Properties
Code Page
LCID
SessionID
Timeout
CodePage : The Codepage property defines the code page that will be used to display the page content in the browser. A code page is a character set containing all the alphanumeric characters and punctuation used by a specific locale
Session.CodePage sets the code page for an entire session. Code pages tell the server how to encode characters for different languagesSession.CodePage [= CodePageID]
Codepage is an integer that represents character formatting code page.
Session.CodePage affects the entire session where as Response.codepage affects the current page.
If codepage is set then charset should also be set
Codeset indicates how to encode
Charset indicates how to decode when displaying responses
The Charset property appends the name of the character set) to the Content-Type header in the Response object.
LCID : The LCID property is used to set or get the locale identifier (LCID) of the page is sent to the browser. The local identifier is used to control how dates, times and currencies will be displayed according to the specific location or region.
SessionId : The SessionID is a read-only property that uniquely identifies each current user's session. Each session has a unique identifier that is generated by the server when the session is created and stored as a cookie on the client machine.
Timeout : The Timeout property sets or returns the timeout period (in minutes) for thе Session object in this application. If the user does not refresh or request a page within the timeout period, the session ends. Can be changed in individual pages as required. The default timeout period is 20 mts.Timeout property can be changed using following syntax
Session. Timeout = (no of minutes)
3. Methods
Abandon: To end a session immediately or to destroy the session objects,we use the Abandon method in the script
Remove:to remove any particular item from session collection we use remove method
Remove All:to remove all the items from sessions contents collection we go for session.removeall()
No comments:
Post a Comment