<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 值。

ASP.NET AJAX 客户端脚本库不支持使用编码到 URL 中的 Cookie 的设置。
 
说明
AutoDetect如果浏览器或设备支持 Cookie,但当前禁用了 Cookie,则请求功能仍会使用 Cookie。
UseCookies无论浏览器或设备是否支持 Cookie,都使用 Cookie 来保留用户数据。
UseDeviceProfileHttpBrowserCapabilities 设置指示浏览器或设备支持 Cookie,将使用 Cookie;否则,将在查询字符串中使用一个标识符。
UseUri无论浏览器或设备是否支持 Cookie,调用功能都使用查询字符串来存储标识符。
  • cookieName

  • customProvider

String 特性。

mode

Session State Modes。

InProc 值。

说明
Custom会话状态正在使用自定义数据存储来存储会话状态信息。
InProc会话状态正在处理 ASP.NET 辅助进程。
Off会话状态被禁用。
SQLServer会话状态正在使用进程外 SQL Server 数据库存储状态信息。
StateServer会话状态将使用进程外 ASP.NET 状态服务来存储状态信息。
  • 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;"
sessionState 节,以帮助保护sqlConnectionString 值。

  • stateConnectionString

String 特性。

Session State Modes。

sessionState 节,以帮助保护stateConnectionString 值。

  • 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。

在 .NET Framework 1.1 版中,如果 mode 特性设置为 SQLServer,并且客户端模拟有效,则 ASP.NET 使用来自 ASP.NET 客户端模拟的客户端凭据连接到运行 SQL Server 的计算机。

子元素

元素

说明

providers

包含自定义会话状态存储提供程序的集合。

 

 

 

父元素

元素

说明

configuration

公共语言运行时和基于 .NET Framework 的应用程序所使用的每个配置文件中均需要的根元素。

system.web

指定配置文件中 ASP.NET 配置设置的根元素,并且包含各种元素,这些元素配置 ASP.NET Web 应用程序并控制应用程序的行为方式。

 
 
 
 
 
 
 
 
<sessionState> 元素配置当前应用程序的会话状态设置。

<sessionState> 元素控制 ASP.NET 应用程序如何为每个客户端建立并保持这种关联。

这种机制非常灵活,可以为您提供许多功能,其中包括承载进程外的会话状态信息,以及在不使用 Cookie 的情况下跟踪状态。

如果匿名标识票证、Forms 身份验证票证、会话 ID 和用户数据的组合超过了允许的最大 URI 长度,请求将失败,并发出“400 错误的请求”错误。

使用 StateServer 模式

  1. 在将要存储会话状态信息的远程服务器上,确保 ASP.NET 状态服务正在运行。

    ASP.NET 状态服务随 ASP.NET 一起安装,默认情况下位于 %windir%\Microsoft.NET\Framework\version\aspnet_state.exe 中。

使用 SQLServer 模式

  1. 在运行将要存储会话状态的 SQL Server 的计算机上运行 InstallSqlState.sql。

    默认情况下,InstallSqlState.sql 位于 %windir%\Microsoft.NET\Framework\version 中。

    这将创建一个具有新存储过程的名为 ASPState 的数据库,并在 TempDB 数据库中创建名为 ASPStateTempApplications 和 ASPStateTempSessions 的表。

  2.  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" />

相关文章: