asp.net中session的储存位置的选择

一、Session(存在本机内存)

 改配置文件(web.config) 

<configuration>

         <system.web>

                   <compilation debug="true" targetFramework="4.0"/>

                   <sessionState timeout="20" cookieless="false" mode="InProc"></sessionState>

         </system.web>

</configuration>

 

二、Session(存在数据库中)

1、  注册数据库

开始Microsoft Visual Studio 2010Visual Studio Tools Visual Studio 命令提示(2010)

   执行aspnet_regsql.exe -S localhost –E -ssadd -sstype p

(在MSDN中搜索httpsessionstate ==> HttpSessionState 类 (System.Web.SessionState) ==> ASP.NET 会话状态概述 会话状态模式有相应的解释)

2、看到数据库中多了一个数据库aspstate(存session,改配置文件(web.config

<configuration>

         <system.web>

                   <compilation debug="true" targetFramework="4.0"/>

                   <sessionState timeout="20" cookieless="false" mode="SQLServer" allowCustomSqlDatabase="true" sqlConnectionString="server=数据库服务器ip; database=aspstate;user=sa; pwd=accp"></sessionState>

         </system.web>

</configuration>

 

三、Session(存在会话服务器中)

1、  会话服务器开启服务(ASP.NET 状态服务)

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\设置AllowRemoteConnection为一个非零的值

重启asp.net状态服务

2、改配置文件(web.config)

<configuration>

         <system.web>

                   <compilation debug="true" targetFramework="4.0"/>

                   <sessionState timeout="20" cookieless="false" mode="StateServer" stateConnectionString="tcpip=会话服务器ip:42424"></sessionState>

         </system.web>

</configuration>      

 

 

posted @ 2012-03-22 11:08  赵志龙  阅读(352)  评论(0编辑  收藏  举报