• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

asp.net网站使用redis存储session

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1、下载windows redis 并安装

地址:https://github.com/microsoftarchive/redis/releases/tag/win-3.2.100

第二步:使用nuget安装Microsoft.Web.RedisSessionStateProvider

 

第三步:安装完成后配置web.config

 <sessionState mode="Custom" customProvider="MySessionStateStore">
      <providers>
        <!-- For more details check https://github.com/Azure/aspnet-redis-providers/wiki --><!-- Either use 'connectionString' OR 'settingsClassName' and 'settingsMethodName' OR use 'host','port','accessKey','ssl','connectionTimeoutInMilliseconds' and 'operationTimeoutInMilliseconds'. --><!-- 'throwOnError','retryTimeoutInMilliseconds','databaseId' and 'applicationName' can be used with both options. --><!--
          <add name="MySessionStateStore" 
            host = "127.0.0.1" [String]
            port = "" [number]
            accessKey = "" [String]
            ssl = "false" [true|false]
            throwOnError = "true" [true|false]
            retryTimeoutInMilliseconds = "5000" [number]
            databaseId = "0" [number]
            applicationName = "" [String]
            connectionTimeoutInMilliseconds = "5000" [number]
            operationTimeoutInMilliseconds = "1000" [number]
            connectionString = "<Valid StackExchange.Redis connection string>" [String]
            settingsClassName = "<Assembly qualified class name that contains settings method specified below. Which basically return 'connectionString' value>" [String]
            settingsMethodName = "<Settings method should be defined in settingsClass. It should be public, static, does not take any parameters and should have a return type of 'String', which is basically 'connectionString' value.>" [String]
            loggingClassName = "<Assembly qualified class name that contains logging method specified below>" [String]
            loggingMethodName = "<Logging method should be defined in loggingClass. It should be public, static, does not take any parameters and should have a return type of System.IO.TextWriter.>" [String]
            redisSerializerType = "<Assembly qualified class name that implements Microsoft.Web.Redis.ISerializer>" [String]
          />
        --><add name="MySessionStateStore"   type="Microsoft.Web.Redis.RedisSessionStateProvider" host="127.0.0.1" port="6379" operationTimeoutInMilliseconds="120" accessKey="" ssl="false" />
     </providers>
    </sessionState>

  第四步:配置后,登陆;查看是否成功 :进入redis安装文件夹,打开命令窗口 运行: redis-cli  然后输入 keys * 查询

如在代码中使用 Session["redissession"] = "sa";

则生成两个Hash key 

如在代码中使用 Session["redissession"] = "sa";

则生成两个Hash key 

其中wmhe4v0zvbbfinkdnckutv4l就是ASP.NET_SessionId,通过监视请求也可以看见

 

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
七天学会ASP.NETMVC(二)——ASP.NETMVC数据传递发布时间:2022-07-10
下一篇:
ASP.NET MVC V2 Preview 1 发布 期望VS有更好的表现发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap