Create and configure an ASP. NET Session status database
ASP. NET Web application development, we need to store the Session in the database for multiple Web applications to call, the following is the configuration method and precautions.
1. Create a database for storing ASP. NET sessions (both remote and local)
Run the following command in the Windows \ Microsoft. NET \ Framework/V2.0.50727 directory:
Aspnet_regsql.exe-S <SQL Server IP>-U <User Name>-P <Password>-E-ssadd-sstype c-d <Database Name>
After the command is executed, the database for storing the ASP. NET Session variable is successfully created.
2. configuration items in the Web. Config file
Modify the sessionState configuration item in the Web. Config file of the ASP. NET Web application to make the Session State database take effect.
The configuration node is as follows:
Reference content is as follows: <SessionState mode = "SQLServer" SqlConnectionString = "server = <Server IP>; database = <Database Name>; uid = <User Name>; pwd = <Password> ;" AllowCustomSqlDatabase = "True" Cookieless = "false" Timeout = "20"/> |
3. Note that when conducting system tests (mainly load tests), you need to adjust the corresponding time-out configuration items of SQL Server to adapt to the load as the database access load increases. (The default value is 10. Adjust it appropriately .)
ASP. NET Session Status Database Data Model
1. ASPStateTempSessions table definition
Column name |
Type |
Description |
SessionId |
Nvarchar (88) |
Session ID + application ID |
Created |
Datetime |
Date and time session was created (UTC) |
Expires |
Datetime |
Date and time session expires (UTC) |
LockDate |
Datetime |
UTC date and time session was locked |
LockDateLocal |
Datetime |
Local date and time session was locked |
LockCookie |
Int |
Lock ID |
Timeout |
Int |
Session timeout in minutes |
Locked |
Bit |
1= Session locked,0= Session not locked |
SessionItemShort |
Varbinary (7000) |
Serialized session state (if <= 7,000 bytes) |
SessionItemLong |
Image |
Serialized session state (if> 7,000 bytes) |
Flags |
Int |
Session state flags (1= Uninitialized session) |
2. ASPStateTempApplications table definition
Column name |
Type |
Description |
AppId |
Int |
Application ID |
AppName |
Char (280) |
Application name |