AspnetSession

Aspnet Session使用汇总
 
SQLServer示例:
第一步:新建Session.DB
cmd:  aspnet_regsql.exe -S "127.0.0.1" -U sa -P "123456" -d SZSafeSession -ssadd -sstype c
第二步:配置DB连接
web.config:   
<add name="NJmetroSessionContext" connectionString="data source=.;initial catalog=AspnetTestSession;user id=sa;password=123456" providerName="System.Data.SqlClient" />
第三步:引用Session.DB
web.config:   <sessionState mode="SQLServer" sqlConnectionString="SessionDBConnectionString" timeout="20" />

 

InProc示例:

启动AspnetSession服务

<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" cookieless="UseCookies" timeout="36000" />
<sessionState mode="InProc" stateConnectionString="tcpip=10.1.1.125:42424" cookieless="UseCookies" timeout="36000" />

 

Redis示例:

1.通过nuget安装RedisSessionStateProvider
2.Redis配置
3.会话配置
<sessionstate timeout="1" mode="Custom" 
customprovider="RedisSessionStateProvider" cookieless="false">
      <providers>
        <add name="RedisSessionStateProvider" writeexceptionstoeventlog="false" 
        type="RedisProvider.SessionProvider.CustomServiceProvider" 
        server="localhost" port="6379" password="pasword">
      </add> </providers>
</sessionstate>
注意,此密码是可以选择的,看服务器是否需要认证

 

posted @ 2024-07-04 13:41  李文学  阅读(2)  评论(0编辑  收藏  举报