日期:2014-05-20  浏览次数:20686 次

Session 在服务器保存的几种模式是什么啊
Session 在服务器保存的几种模式是什么啊

------解决方案--------------------
ASP.NET session state supports several different storage options for session data. Each option is identified by a value in the SessionStateMode enumeration. The following list describes the available session state modes:

InProc mode, which stores session state in memory on the Web server. This is the default.

StateServer mode, which stores session state in a separate process called the ASP.NET state service. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.

SQLServer mode stores session state in a SQL Server database. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.

Custom mode, which enables you to specify a custom storage provider.

Off mode, which disables session state.

有四种模式,InProc、StateServer、SQLServer、Custom
Off算是不使用。
1、InProc 是默认模式,Session数据保存在本地进程中,几种方式中,只有这种方式支持Session_OnEnd事件。需要注意的是,如果设置webGarden为true,则不能用InProc模式,不然数据会出现丢失。
2、StateServer 在进程中存储,改进程和Asp.net工作进程及IIS没有关系,是为了保证Asp.net或者IIs进程出现问题时,Session能够继续使用(比如有其它负载均衡服务器)。使用这种模式,需要保证该服务器上ASP.NET state service 启动。建议加密sessionState 配置节来保护stateConnectionString 。注意,如果想保存对象在Session中,该对象必要是可序列化的。另外,如果你是大型网站或者应用,需要负载服务器,那么需要共用Session,这时需要设置machineKey,来保证Session一致。
3、SqlServer 存储数据到数据库中,保证ASP.NET session state database 安装在服务器上。使用Aspnet_regsql.exe即可安装,别的和StateServer相似。注意,如果有负载均衡,则所有服务器上的Web程序的目录结构需要一致。
4、Custom 需要自己处理Session,通过设置customProvider来指定处理程序。
5、Off 禁用Session。
------解决方案--------------------
原来asp.net的session有这么好的机制..