Use SQL Server to store ASP. NET Session Variables

Source: Internet
Author: User
Tags table definition

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.