使用自定义 SessionStateStoreProvider 清理过期会话

发布于 2024-08-26 02:47:25 字数 253 浏览 2 评论 0原文

我正在使用无模式数据库实现我自己的 SessionStateStoreProvider 。从文档中很难看出,但似乎我必须有一个单独的过程来清理过期的会话,因为数据库无法通知会话状态存储会话已过期。

我这件事有错吗?我还没有看到替代 SetItemExpireCallback 方法的示例。

I'm implementing my own SessionStateStoreProvider with a schemaless database. It's a little hard to tell from the documentation but it seems as though I will have to have a separate process for cleaning up expired sessions since the database will not have a way to notify the session state store that a session has expired.

Am I wrong about this? I haven't seen an alternative example for overriding the SetItemExpireCallback method.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

似狗非友 2024-09-02 02:47:25

是的,我相信这是正确的。

如果将会话存储在数据库上,则 Sql Server 代理上有一个作业每分钟左右调用此过程:

    DECLARE @now datetime
    SET @now = GETUTCDATE()

    DELETE ASPStateTempSessions WHERE Expires < @now

没有会话过期的触发器。可以说这是一个触发器,它可以在哪里?没有地方可以单独放置该触发器来了解会话已过期并自动删除其自身。

另一方面,您可以做的不是创建计时器,而是当用户请求页面时,每隔 1-2 分钟触发一个函数来删除过期的页面。

因此,您可以从用户调用中触发触发器,但必须使用某种锁定使其每 1-2 分钟仅运行一次,并检查最后一次运行。

希望那有帮助。

Yes I believe that is correct.

If you store the sessions on database, then there is a Job on Sql Server Agent thats call this procedure every minute or so:

    DECLARE @now datetime
    SET @now = GETUTCDATE()

    DELETE ASPStateTempSessions WHERE Expires < @now

There is no trigger for session expired. Lets say that was a trigger, where that can be ? There is no place to put that trigger alone to understand that the session expired and auto-delete his self.

From the other hand what you can do, is not to create a timer, but when a user ask for a page, every 1-2 minute, trigger a function to delete the expired ones.

So you make a trigger from a user call, but you must make it run only onces every 1-2 minutes using some kind of lock, and check for the last run.

Hope thats helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文