且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

注销后清除会话

更新时间:2023-11-09 08:23:52

答案始终是相同的.您需要设置页面,以便不对其进行缓存.如果您对问题进行了搜索,则可以找到包含此信息的任意数量的页面:

Response.Cache.SetCacheability(HttpCacheability.NoCache)

Google真是太好了.
The answer to this is always the same. You need to set your pages so they are not cached. If you''d googled the problem, you''d have found any number of pages with this info on it:

Response.Cache.SetCacheability(HttpCacheability.NoCache)

Google is a wonderful thing.




这是一种解决方案,可能会对您有所帮助.

在母版页加载"事件中,检查session ["username"] ="或session ["username"] = null.

如果是这样,请重定向到登录页面.

Hi,

Here is one solution, this might help you.

In Master Page Load event check if session["username"] = "" or session["username"] = null.

If so, redirect to Login Page.

if (session["username"] = "" || session["username"] = null)
{
Response.Redirect("~\Login.aspx")
}



注意:不应对Login.aspx页使用相同的母版页.



Note: You should not use the same Master Page for Login.aspx page.


好,不要依赖Session.abandon.无需执行此操作,而是使用会话变量并检查会话变量在任何请求中是否可用.

我的意思是:

假设有人登录时设置了
Session["IsLoggedIn"] = true;

现在,对于任何请求,请检查IsLoggedIn.

当用户注销时,将值IsLoggedIn 重置为false,并将其他变量设置为null.

这样,您将绝对确保即使Session.Abandon无法正常工作,您的用户也不会连接到上一个会话.
Well, Dont rely on Session.abandon. Rather than doing this you use a Session Variable and check if session variable is available in any request.

I mean :

Say when someone logs in you set
Session["IsLoggedIn"] = true;

Now for any request, check for IsLoggedIn.

When the user logs out, reset the value IsLoggedIn to false and set other variables to null.

In this way you will be absolutely sure that your user does not connect to the previous session even though Session.Abandon does not work.