简体   繁体   English

如何结束用户会话并确保用户已注销?

[英]How to end the user session and make sure that the user is logged out?

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. 我是.aspx的新手,现在问题是因为我正在做一个支持Web的项目,我从用户那里登录。 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. 现在我甚至在右上角使用了一个超链接“Logout”,然后将其转移到Login页面。 ( 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. 现在,如果在网上运行,我可以轻松登录,但是当我通过超级链接“注销”注销时,它会再次进入“登录”页面,但如果我按下浏览器的后退按钮,它会再次将控件传输到数据页面,我可以再次执行数据操作。

I used this 我用过这个

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

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.. 我在没有任何.net或aspx知识的情况下指导了这个项目,我仍在学习所有内容,请提前表达我的怀疑。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 会话无效,因为用户已注销 - The session is invalid because the user logged out 如何使MVC退出已登录的用户? - How do I make MVC to sign out a logged in user? 如何确保只有用户登录才能下载文件? (没有表格认证) - How Can I make sure a file can be downloaded only if the user is logged in? ( no forms authentication ) 如何找到已登录的Windows用户的会话名称? - How to find the session name of the logged in Windows user? 如何持久保存整个会话的登录用户数据? - How to persist logged in user data for entire session? 验证访问令牌时出错:session 无效,因为用户已注销 - Error validating access token: The session is invalid because the user logged out 如何找出登录机器的用户名? - How to find out the name of the user logged on the machine? ASP.NET MVC4 - Session_End - 如何在Global.asax的Session_End中获取当前登录用户的名称? - ASP.NET MVC4 - Session_End - How can I get the currently logged on user's name in Session_End of Global.asax? 用户会话结束时如何保留数据 - how to persist data when user session end 用户登录但后来从数据库中删除时如何清除会话 - How to clear session when user is logged in but later deleted from the database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM