How to clear SQL session state for all users in ASP.NET

守給你的承諾、 提交于 2019-12-03 17:00:55

You can call Session.Abandon, or Clear for every user when they hit the invalid Session object.

You can also loop through the per-user Session collection, and clear the keys that can contain "old" objects. Maybe you have a login ticket and such that you don't want to clear.

foreach (string key in Session.Keys)
{
  if (!key.Equals("login"))
  {
    Session.Remove(key);
  }
}

You may try using stored procedure in SQL Server to clear all the sessions:

CREATE PROCEDURE [dbo].[DeleteSessions]
AS
DELETE [ASPState].dbo.ASPStateTempSessions

RETURN 0
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!