|
创建和配置ASP.NET Session状态数据库
在基于NLB(网络负载平衡)环境下的ASP.NET Web应用程序开发,我们需要将Session存储在数据库中供多个Web应用程序调用,以下为配置方法及注意事项。
1.创建用于存储ASP.NET Session的数据库(远程、本地皆可,使用数据库用户身份认证)
在Windows\Microsoft.NET\Framework/V2.0.50727目录下使用如下命令:
aspnet_regsql.exe -S -U -P -E -ssadd -sstype c -d
命令执行后就会成功建立起用于存储ASP.NET Session变量的数据库了。
2.Web.Config文件配置项
我们需要在ASP.NET Web应用程序中的Web.Config文件修改sessionState配置项以使Session状态数据库生效。
配置节点如下:
3.注意在进行系统测试(主要是负载测试)的时候,因为数据库访问负载的增加,需要调整SQL Server相应超时的配置项以适应负载。(默认值为10,请适度进行调整。)
ASP.NET Session状态数据库数据模型
1.ASPStateTempSessions表定义
列名类型描述SessionIdnvarchar(88)Session ID + application IDCreateddatetimeDate and time session was created (UTC)ExpiresdatetimeDate and time session expires (UTC)LockDatedatetimeUTC date and time session was lockedLockDateLocaldatetimeLocal date and time session was lockedLockCookieintLock IDTimeoutintSession timeout in minutesLockedbit1=Session locked, 0=Session not lockedSessionItemShortvarbinary(7000)Serialized session state (if 7,000 bytes)FlagsintSession state flags (1=Uninitialized session)
2.ASPStateTempApplications表定义
列名类型描述AppIdintApplication IDAppNamechar(280)Application name
3.使用的存储过程
[table][tr]Stored ProcedureDescription[/tr][tr][td=1,1,49%]CreateTempTables[/td][td=1,1,51%]Creates the ASPStateTempSessions and ASPStateTempApplications tables; called during setup, but not called by SqlSessionStateStore.[/td][/tr][tr][td=1,1,49%]DeleteExpiredSessions[/td][td=1,1,51%]Used by SQL Server Agent to remove expired sessions.[/td][/tr][tr][td=1,1,49%]GetHashCode[/td][td=1,1,51%]Hashes an application name and returns the hash; called by TempGetAppID.[/td][/tr][tr][td=1,1,49%]GetMajorVersion[/td][td=1,1,51%]Returns SQL Server's major version number.[/td][/tr][tr][td=1,1,49%]TempGetAppID[/td][td=1,1,51%]Converts an application name into an application ID; queries the ASPStateTempApplications table and inserts a new record if necessary.[/td][/tr][tr][td=1,1,49%]TempGetStateItem[/td][td=1,1,51%]Retrieves read-only session state from the database (ASP.NET 1.0; ASP.NET 1.1/SQL Server 7).[/td][/tr][tr][td=1,1,49%]TempGetStateItem2[/td][td=1,1,51%]Retrieves read-only session state from the database (ASP.NET 1.1).[/td][/tr][tr][td=1,1,49%]TempGetStateItem3[/td][td=1,1,51%]Retrieves read-only session state from the database (ASP.NET 2.0).[/td][/tr][tr][td=1,1,49%]TempGetStateItemExclusive[/td][td=1,1,51%]Retrieves read/write session state from the database (ASP.NET 1.0; ASP.NET 1.1/SQL Server 7).[/td][/tr][tr][td=1,1,49%]TempGetStateItemExclusive2[/td][td=1,1,51%]Retrieves read/write session state from the database (ASP.NET 1.1).[/td][/tr][tr][td=1,1,49%]TempGetStateItemExclusive3[/td][td=1,1,51%]Retrieves read/write session state from the database (ASP.NET 2.0).[/td][/tr][tr][td=1,1,49%]TempGetVersion[/td][td=1,1,51%]Marker whose presence indicates to ASP.NET 2.0 that the session state database is ASP.NET 2.0-compatible.[/td][/tr][tr][td=1,1,49%]TempInsertStateItemLong[/td][td=1,1,51%]Adds a new session, whose size is > 7,000 bytes, to the database.[/td][/tr][tr][td=1,1,49%]TempInsertStateItemShort[/td][td=1,1,51%]Adds a new session, whose size is |
|