Azure Redis - 如何在模式=自定义时在 ASP.NET 应用程序中模拟 session_end 事件?

Azure Redis - how to simulate session_end event in ASP.NET app when mode=Custom?

与我合作的组织使用 Azure Redis 为其 ASP.NET 站点存储会话信息,这对我来说是新领域(没有任何经验)。

我需要在会话结束时触发一些代码(超时、被放弃等),我读到如果您保存了会话状态,InProc Session_End 将触发,但我们的组织使用自定义设置对于会话状态。像这样:

<sessionState mode="InProc" customProvider="RedisSessionStateStore" stateConnectionString="tcpip=xxxx" sqlConnectionString="xxxx" cookieless="false" timeout="1000">
      <providers> 
        <add name="RedisSessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" connectionString="xxx" applicationName="xxxx" retryTimeoutInMilliseconds="1000" ssl="false" />
      </providers>
</sessionState>

据我了解,Session_End 事件在这种情况下不会触发。除了做一些预定的工作来尝试找到所有被放弃的会话外,还有什么方法可以捕获 Session_End 事件?

Note: The Session_End event is raised only when the sessionstate mode is set to InProc in the Web.config file. If session mode is set to StateServer or SQLServer, the event is not raised.

这就是无法捕获Session_End事件的原因。

我觉得下面的博客,也许对你有用。

Building a Sitecore Redis Session State Provider

只要存储会话数据的 redis 密钥从您的 redis 缓存中过期(或被逐出),您的会话就会过期。因此,您可以使用 redis 密钥 space 通知功能从您的 redis 缓存订阅密钥过期事件。

文档:http://redis.io/topics/notifications

您必须首先在 Azure 中的缓存上启用关键 space 通知,因为它们默认情况下未启用。

文档: https://docs.microsoft.com/en-us/azure/azure-cache-for-redis/cache-configure#keyspace-notifications-advanced-settings