在asp.net中的会话(kill session) [英] Session in asp.net(kill session)

查看:65
本文介绍了在asp.net中的会话(kill session)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友

我正在使用asp.net C#.我想在用户离开该页面时终止当前页面的会话.有任何建议吗?

谢谢

Hello Friends

I am using asp.net C#. I want to kill session of current page when user leave that page. Any suggestions???

Thanks

推荐答案

使用..session.abandon()..用户注销后立即......
use..session.abandon()..as soon as the user logs out...


如果您将进行一些研究,您将被发现,这不可能以您的思维方式进行.为什么?因为发送页面数据后服务器绝对没有与客户端的连接.因此,它不能依赖于客户端上发生的任何事件.唯一可靠的选择是微调会话超时,如果资源开销在您的环境中可以接受,则执行预定的后台Ajax调用以保持会话存活.请注意,以后的方法必须非常仔细地计划.当然,您仍然必须鼓励用户注销后再关闭浏览器窗口.

[更新]
您为什么要取消会话?只需删除它的内容-或保留它.但是问题是相同的,您必须以其他方式解决.离开页面与关闭桌面上的窗口不同.您可以尝试在客户端捕获onunload和onfeboreunload,但不能确保将其触发,并且会得到通知.
您可以确定的是何时加载页面.此时,您可以确定是否是新的仪表板会话,并在需要时重置会话的适当部分.
If you would have been done a little research, you would have been found, that this is not possible in the way you think. Why? Because the server has absolutely no connection to the client after the page data is sent. Thus it can not rely on any event happening on the client. Your only reliable option is to fine-tune the session timeout and, if the resource expenses are acceptable in your environment, to do scheduled background ajax calls to keep the session alive. Be aware that this later approach has to be planed really carefully. Of course, you still have to encourage your users to log out before closing the browser window.

[Update]
Why do you want to kill the session? Just delete it''s content - or leave it. But the problem is the same, and you have to address in other way. Leaving a pages is not the same as closing a window on the desktop. You can try to catch onunload and onfeboreunload on client side, but you can''t be sure that it will be fired, and you get notified.
What you can be sure about is when the page is loaded. At that point you can decide if it is a new dashboard session or not, and reset the proper part of the session if needed.


我不是要在注销时终止会话,我只是想当用户单击任何链接并离开该页面dashobard.aspx并到达dashoarddetails.aspx页面时,是否希望用户位于dashboard.aspx页面上.然后,我在dashobard上使用的会话应该在他离开dashobard页面时终止.那就是我想要的吗?

问候
库玛亲王
助理软件工程师
ENest Technologies
I am not asking to kill session on logout, I just want if user are on dashboard.aspx page when he click on any link and leave this page dashobard.aspx and reach on dashoarddetails.aspx page. Then the session i am using on dashobard should kill when he left dashobard page. That is what i want??

Regards
Prince Kumar
Asst. Software Engineer
ENest Technologies


这篇关于在asp.net中的会话(kill session)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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