如何结束用户会话并确保用户已注销? [英] How to end the user session and make sure that the user is logged out?

查看:375
本文介绍了如何结束用户会话并确保用户已注销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是.aspx的新手,现在的事情是因为我正在做一个启用Web的项目,所以我从用户那里获得了此登录名.我拖放了登录模板,然后使用

I am new to .aspx and now the thing is since i am doing a web enabled project, I have this login from an user. I drag dropped the login template and then used the

Session["Authentication"] = username.Tostring();

存储当前登录用户的信息,依此类推.现在,我什至在右上角使用了注销"超链接,然后将其转移到登录"页面. (如果这是错误的传输方式,请让我知道,我正在通过互联网学习全部内容.)

to store the current logged user's info and so. Now i even used a hyperlink "Logout" at the top right corner and then made it transfer to Login page. ( If this is wrong way of transfering Please Let me know, I am Learning all by internet)..

现在,如果在运行网络时,我可以轻松登录,但是当我通过超链接注销"注销时,它将再次带我到登录"页面,但是如果我按浏览器的后退"按钮,它将再次转移控制权到数据页面,然后我可以再次执行数据操作.

Now if on running the web , i can easily login , but when i logout through hyper link "logout" it will take me to the Login page again, but if i press the back button of the browser it again transfers the control to the data page and i can again perform the data operation's.

我用了这个

Session["Authenticate"] = null

在登录页面的页面加载时,只需单击登录按钮,用户便可以通过

at the page load of the login page so that only at the login button click the user can enter again by

Session["Authenticate"] = username.Tostring();

然后我在数据页的每个页面加载时进行了检查

Then i used a check at each page load of the data pages

if(Session[Authentiacte"] == null)
     Server.Tranfer("LoginPage.aspx");

这不能解决我的问题, 请任何人提供提示,链接或提示以改善我的注销方式? 我在不了解.net或aspx的情况下开始了这个项目,但我仍在学习所有内容,请掩盖我的疑问 提前谢谢..

This didnt solve my problem, Please can anyone give a hint or a link or a tip to improve my way of logout? I strated this project without any knowledge of the .net or aspx and i am still learning everything, please bare my doubts thankx in advance..

推荐答案

HttpContext.Current.Session.Clear();
HttpContext.Current.Session.Abandon();
HttpContext.Current.User = null;
System.Web.Security.FormsAuthentication.SignOut(); // if forms auth is used

这篇关于如何结束用户会话并确保用户已注销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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