c# - Redis session 在20分钟后过期,为什么?

标签 c# azure redis session-state

我使用redis缓存( azure 的服务器)

System.Web.HttpContext.Current.Session["UserID"] = user.Id;

20 分钟后 System.Web.HttpContext.Current.Session["UserID"] 返回 null

我将 Microsoft.Web.RedisSessionStateProvider 用于我的自定义 session 。

当我调用 System.Web.HttpContext.Current.Session["UserID"] 时滑动 session 的最佳方式是什么

<sessionState mode="Custom" customProvider="MySessionStateStore">
  <providers>
    <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="SERVER" accessKey="KEY" ssl="true" throwOnError="false" />
  </providers>
</sessionState>

最佳答案

当我调用变量时,我会同时更新 session 变量,如下所示:

var userId = System.Web.HttpContext.Current.Session["UserID"]; // Get value 
System.Web.HttpContext.Current.Session["UserID"] = userId; // Refresh it immediately to increase timeout

关于c# - Redis session 在20分钟后过期,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27626801/

相关文章:

node.js - 在 Azure 应用服务中部署前端和后端应用程序的最佳方法是什么?

amazon-web-services - Redis——它是如何提高性能的?

Magento 与 RedisLab Redis 集群后端

java - 通过删除 PRIME ASCII 字符来打印字符串

c# - MVC 4 在表单外显示验证摘要?

c# - 如果它是 IDisposable,我可以 "inline"变量吗?

Azure Functions Docker 部署 Linux 工作线程在资源组中不可用

c# - ServiceStack Redis 最新列表(按日期)

entity-framework - 迁移和配置。seed 未在 Azure 部署上运行

redis - 获取 redis 过期通知的值(value)