<sessionState mode="[Off|InProc|StateServer|SQLServer|Custom]" timeout="number of minutes" cookieName="session identifier cookie name" cookieless= "[true|false|AutoDetect|UseCookies|UseUri|UseDeviceProfile]" regenerateExpiredSessionId="[True|False]" sessionIDManagerType="session manager type" sqlConnectionString="sql connection string" sqlCommandTimeout="number of seconds" allowCustomSqlDatabase="[True|False]" useHostingIdentity="[True|False]" stateConnectionString="tcpip=server:port" stateNetworkTimeout="number of seconds" customProvider="custom provider name" compressionEnabled="[True|False]" sqlConnectionRetryInterval="number of seconds"> <providers>...</providers> </sessionState>
allowCustomSqlDatabase
Boolean 特性。
默认值为 false。
compressionEnabled
默认值为 false。
cookieless
UseCookies 值。
- cookieName
- customProvider
String 特性。
mode
Session State Modes。
InProc 值。
- partitionResolverType
默认值为空字符串。
- regenerateExpiredSessionId
默认值为 true。
- sessionIDManagerType
默认值为空字符串。
- sqlCommandTimeout
TimeSpan 特性。
默认值为 0:00:30(30 秒)。
- sqlConnectionRetryInterval
默认值为 0 秒。
- sqlConnectionString
String 特性。
Session State Modes。
您可以从 connectionStrings 节点中将此特性设置为命名 sqlConnectionString,也可以使用下面的语法:
sqlConnectionString="Data Source=.\SQLServer2005;Initial Catalog=SessionState;Integrated Security=SSPI;"
- stateConnectionString
String 特性。
Session State Modes。
- stateNetworkTimeout
TimeSpan 特性。
StateServer 值时使用。
默认值为 10 秒。
timeout
对于进程内和状态服务器模式,timeout 特性不能设置为大于 525,600 分钟(1 年)的值。
同样,更改 ASP 页的会话超时时间不会影响 ASP.NET 页的会话超时时间。
默认值为 20 分钟。
- useHostingIdentity
Boolean 特性。
指定会话状态将恢复为承载标识,还是将使用客户端模拟。
如果为 true,ASP.NET 将使用下列进程凭据之一来连接会话状态存储区:
-
承载进程;对于 Microsoft Internet 信息服务 (IIS) 5 和 5.1 版为 ASPNET,对于 Microsoft Windows Server 2003 为 NETWORK SERVICE。
-
应用程序模拟标识,当使用了以下配置时使用此凭据:
默认值为 true。
子元素
|
元素 |
说明 |
|---|---|
|
providers |
包含自定义会话状态存储提供程序的集合。 |
父元素
|
元素 |
说明 |
|---|---|
|
configuration |
公共语言运行时和基于 .NET Framework 的应用程序所使用的每个配置文件中均需要的根元素。 |
|
system.web |
指定配置文件中 ASP.NET 配置设置的根元素,并且包含各种元素,这些元素配置 ASP.NET Web 应用程序并控制应用程序的行为方式。 |
<sessionState> 元素控制 ASP.NET 应用程序如何为每个客户端建立并保持这种关联。
这种机制非常灵活,可以为您提供许多功能,其中包括承载进程外的会话状态信息,以及在不使用 Cookie 的情况下跟踪状态。
如果匿名标识票证、Forms 身份验证票证、会话 ID 和用户数据的组合超过了允许的最大 URI 长度,请求将失败,并发出“400 错误的请求”错误。
使用 StateServer 模式
-
在将要存储会话状态信息的远程服务器上,确保 ASP.NET 状态服务正在运行。
ASP.NET 状态服务随 ASP.NET 一起安装,默认情况下位于 %windir%\Microsoft.NET\Framework\version\aspnet_state.exe 中。
-
使用 SQLServer 模式
-
在运行将要存储会话状态的 SQL Server 的计算机上运行 InstallSqlState.sql。
默认情况下,InstallSqlState.sql 位于 %windir%\Microsoft.NET\Framework\version 中。
这将创建一个具有新存储过程的名为 ASPState 的数据库,并在 TempDB 数据库中创建名为 ASPStateTempApplications 和 ASPStateTempSessions 的表。
-
Note
可以使用 Aspnet_regsql.exe 来完成这些步骤。
System.Web.SessionState。
默认配置
而是由应用程序返回的默认配置。
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" stateNetworkTimeout="10" sqlConnectionString="data source=127.0.0.1;Integrated Security=SSPI" sqlCommandTimeout="30" customProvider="" cookieless="UseCookies" cookieName="ASP.NET_SessionId" timeout="20" allowCustomSqlDatabase="false" regenerateExpiredSessionId="true" partitionResolverType="" useHostingIdentity="true"> <providers> <clear /> </providers> </sessionState>
下面的示例演示如何指定会话状态配置设置。
<sessionState mode="SQLServer" cookieless="true" sqlConnectionString=" Integrated Security=SSPI;data source=MySqlServer;" sqlCommandTimeout="10" />