Session information

   

There are some things about session variables that are important to know. Each session can be uniquely identified within an ASP.NET application. A 120-bit session ID string, which contains characters that can be carried in a URL, is used to track and identify sessions. Session ID values are generated by an algorithm that guarantees uniqueness. This is important in ensuring that sessions don't collide.

Session IDs are communicated across client/server requests by either an HTTP cookie or a munged URL.

An application can store session state data in a SQL Server database. The following procedure shows how to configure an application to use SQL Server to store state:

  1. Be sure ASP.NET State service is running on the server that will store the session. This service is installed with ASP.NET and installed by default at <Drive>:\Program Files\ASP.NET\Premium\V1.0Beta2\aspnet_estate.exe.

  2. Edit the Web.config file as follows :

     <sessionState mode="OffInprocStateServerSQLServer"    cookieless="truefalse"    timeout="number of minutes"    stateConnectionString="tcpip=server:port"    sqlConnectionString="sql connection string" /> 

Be sure you specify the sqlConnectionString as sqlConnectionString="data source=somename; user id=sa;password=MyPassword" in Web.config of the application.

Table 17.1 shows traits of the required attribute for the sessionState element, and Table 17.2 shows traits of the optional attributes for the sessionState element.

Table 17.1. Required Attribute for sessionState

Attribute

Option

Description

Mode

 

Specifies where to store the session state.

 

Off

Indicates that session state is not enabled.

 

Inproc

Indicates that session state is stored locally.

 

StateServer

Indicates that session state is stored on a remote server.

 

SQLServer

Indicates that session state is stored on the SQL Server.

Table 17.2. Optional Attributes for sessionState

Attribute

Option

Description

cookieless

 

Specifies whether sessions without cookies should be used to identify client sessions.

 

true

Indicates that sessions without cookies should be used.

 

false

Indicates that sessions without cookies should not be used. The default is false.

timeout

 

Specifies the number of minutes a session can be idle before it is abandoned . The default is 20.

StateConnectionString

 

Specifies the server name and port where session state is stored remotely. For example, "tcpip=127.0.0.1:42424" . This attribute is required when mode is StateServer.

SqlConnectionString

 

Specifies the connection string for a SQL Server. For example, "data source=127.0.0.1;user id=sa;password=" . This attribute is required when mode is SQLServer.

   


Special Edition Using ASP. NET
Special Edition Using ASP.Net
ISBN: 0789725606
EAN: 2147483647
Year: 2002
Pages: 233

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net