注销后清除会话 [英] Clearing session after logout

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

问题描述



我有一个注销按钮,在click事件中,我清除了所有会话变量并将页面重定向到登录页面.但是注销后,当我单击后退"按钮时,它将转到上一个访问的页面.这是几个人面临的非常普遍的问题,但我无法解决.我尝试了以下所有选项,

Hi,

I have a logout button and in the click event I have cleared all session variables and redirected page to login page. But after logout, when I click back button, it goes to the previous page accessed. This is a very common problem several people facing but I couldn''t solve it. I tried all of the below options,

session["username"] = "";
session.clear();
session.abandon();



尝试在Global.ascx中提供这些内容,
删除了iis会话超时设置..

但是以上都不起作用.它再次回到上一页.
而且我的退出按钮在母版页中,因此无法在浏览器中禁用后退按钮.如果有人解决了该问题,请提供帮助以解决该问题.



Tried giving these in Global.ascx,
Removed the iis session timeout setting..

But none of the above is working. It again goes back to prevous page.
And I can''t disable the back button in browser since my logout button is in master page. If anyone has solved this problem, please do help to come out of this problem.

推荐答案

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

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.


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

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