单击注销按钮时如何关闭会话? [英] How to close session when logout button clicked?

查看:61
本文介绍了单击注销按钮时如何关闭会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#开发一个简单的基于HRMS网络的应用程序。在此应用程序中,没有实现会话。我的应用程序中有一个母版页面,在母版页面上有一个名为 LogOut 的菜单按钮,当我点击该按钮时,它会将我重定向到应用程序的索引页面。当我关闭浏览器标签并再次复制相同的网址时,它实际上打开了我要打开的页面,但没有按预期打开 login 页面。

注意:应用程序中没有注销页面,我只是在点击注销时将其重定向到index.aspx页面。

所以请告诉我如何实现会话以避免这个。



这里有一些用户点击登录时的代码:

I am developing a simple HRMS web based application in C#. In this application there is no session implemented. There is master Page in my application and on the master page there is a menu button named LogOut , when i click to that button it redirect me to the index page of the application. and when i close the browser tab and again copy the same url it actually opens the page whatever page i want to open but not open the login page as expected.
Note: There is no logout page in the application, i am just redirecting it to the index.aspx page when logout clicked.
So please tell me how could i implement session to avoid this.

Here some code when user click to logiut:

<li><a href="Index.aspx">Logout</a></li>

推荐答案

您好,

如果您对会话事件有任何了解,请尝试实施。

Hello ,
If you know any thing about session events try to implement it.
Session.Clear();





Session.RemoveAll();

否则一个简单的方法就是保持隐藏字段中的用户ID。单击登录时,将该值保留在隐藏字段中。单击注销时,从隐藏字段中删除该值。

虽然尝试实现它会话。这个隐藏字段概念不符合标记。


Or
Session.RemoveAll();
Otherwise a simple approach would be to keep the userid in hidden field . When Clicked on Login keep that value in hidden field. When clicked on logout ,remove the value from hidden field.
Although try to Implement It The session.This Hidden field concept is not upto the mark.


在页面加载时检查会话是否为空。



示例:



On page load check whether session is null or not.

Example :

If Session("XXXXX") Is Nothing Then Response.Redirect("Login.aspx")


你可以使用
Session.Abandon();


这篇关于单击注销按钮时如何关闭会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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