目前我有一个客户端和管理网页。有多个用户将登录到客户端页面。在管理页面中,当我在管理页面中恢复数据库时,我需要注销当前登录到客户端页面的所有用户。任何想法应该如何做?我目前使用的语言是经典的 ASP。如果它可以在 ASP.NET 中完成,那也很好。谢谢。
2 回答
这真的取决于你缓存了什么。如果是数据,那么您可以清除缓存的数据,而不是强制您的用户再次登录。
如果是数据或权限/安全更改,那么您可以在数据库中有一个名为 SchemaVersion 的设置,用于存储数据库的当前版本。每个登录用户对应用程序的请求都可以将 cookie/会话版本与数据库中的版本进行比较,如果不同,则让客户端删除会话/cookie 并强制重新登录。
根据 Microsoft 帮助文章,您可以像这样重置会话:
Session.Abandon();
Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));
从 MSDN 你可以像这样清除你的 cookie:
if (HttpContext.Current.Request.Cookies["MyCookieName"] != null)
{
HttpCookie aCookie = HttpContext.Current.Request.Cookies["MyCookieName"];
aCookie.Expires = DateTime.Now.AddDays(-10);
aCookie.Value = "";
HttpContext.Current.Response.Cookies.Add(aCookie);
}
这应该强制登录,但我自己还没有确认。
因此,总而言之,您可以使用 ASP.NET 缓存来存储数据库架构版本,并且:
在页面加载开始时调用一个帮助类LoginResetHelper.IsDbValid()
来查看我们是否需要再次登录
在助手类中,您会问
if (Cache["SchemaVersion"] == null)
{
// retrieve schemaVersion from db
Cache.Add("SchemaVersion", schemaVersion);
}
HttpCookie oCookie = new HttpCookie("ClientSchemaVersion");
if (Cache["SchemaVersion"] == oCookie.Value)
return true;
return false;
如果 IsDbValue 为真,则继续正常
如果为假,则调用LoginResetHelper.ResetLogin()
并重定向到登录页面。
ResetLogin()
你会执行我上面提到的清算功能
Maybe easiest way is to define an Application
variable indicating your website in under maintenance and, in every page through a server side include, check that variable and redirect to an appropriate error page.