gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 11:38:31 30 4
gpt4 key购买 nike

我使用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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com