强制用户注销 [英] force users to logout

查看:315
本文介绍了强制用户注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有一个客户端和管理网页。有多个用户谁将会登录到客户端页面。而在管理页面,当我恢复了管理页面数据库里面,我需要注销所有谁正在登录到客户端页面的用户。任何想法,应该怎么做?我目前使用的语言是传统的ASP。如果它可以在ASP.NET,其优良的完成了。谢谢你。

Currently I have a client and admin webpage. There are multiple users who will login to the client page. While in admin page, when I restored the database inside the admin page, I need to logout all the users who are currently login to the client page. Any ideas how it should be done? My current language using is classic ASP. If it can be done in ASP.NET, its fine too. Thanks.

推荐答案

这真的取决于你什么缓存。如果它的数据,那么您可以清除缓存的数据,而不是迫使用户重新登录。

It really depends what you've cached. If it's data then you can clear the cached data rather than forcing your users to login again.

如果它的数据或权限/安全性的变化,那么你可以在你的数据库称为SchemaVersion存储数据库的当前版本的设置。在用户请求到应用程序的每个记录可以比较反对一个在数据库中的Cookie /会话版本,如果它不同于获取客户端删除会话/ cookie,并强制重新登录。

If it's data or permissions / security change then you could have a setting in your database called SchemaVersion that stores the current version of the database. Each logged in user request to the app could compare the cookie / session version against the one in the database and if it differs to get the client to delete the session / cookie and force a re-login.

据微软的帮助文章您可以重置会话这样的:

According to a Microsoft help article you can reset the session like this:

Session.Abandon(); 
Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));

和从MSDN可以清除您的Cookie 这样的:

And from MSDN you can clear your cookie like this:

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);
}

这应该强制登录,但我还没有证实这个自己。

This should force a login, but I haven't confirmed this myself.

因此​​,在总结,你可以使用ASP.NET缓存来存储数据库架构版本和:

So in summary, you can use the ASP.NET Cache to store the db schema version and:

在页面加载的开始调用一个辅助类 LoginResetHelper.IsDbValid()来看看我们是否需要重新登录

At the start of the page load call a helper class LoginResetHelper.IsDbValid() to see if we need to login again

在辅助类,你会问

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为真,则继续正常

If IsDbValue is true, the continue as normal

如果它是假的,然后调用 LoginResetHelper.ResetLogin()并重定向到登录页面。

If it is false, then call the LoginResetHelper.ResetLogin() and redirect to login page.

ResetLogin()您将执行我在上面

这篇关于强制用户注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆