会话如何注销页面 [英] How to logout the page if the session

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

问题描述



如果会话已过期,如何在asp.net中注销页面.

我已经在母版页中提到了代码.但是,即使会话存在,它也总是注销页面.

参见代码.

Masterpage.master
------------------
< script type ="text/javascript">
函数SessionTimeOuts()
{
self.setTimeout("RedirectToLogin();",您希望在此处放置的任何时间段");
}
函数RedirectToLogin()
{
alert(``您的会话已过期.'');
window.location.href =''login.aspx''
//要重定向的任何页面
}

</script>

< body class ="Bodybgcolor"önload=''SessionTimeOuts()''>

请帮助解决此问题.

问候,
Ganesh.S

Hi,

How to logout the page if the session has expires in asp.net.

I have mentioned the code in master page. but, it''s always logut the page even if the session exists.

See the code.

Masterpage.master
------------------
<script type="text/javascript">
function SessionTimeOuts()
{
self.setTimeout("RedirectToLogin();", ''any time period you wish to put here'');
}
function RedirectToLogin()
{
alert(''Your session has expired.'');
window.location.href = ''login.aspx''
//any page where you want the redirection
}

</script>

<body class="Bodybgcolor" önload=''SessionTimeOuts()''>

Pls. help to resolve this issue.

Regards,
Ganesh.S

推荐答案

请参阅我最近关于类似Session问题的答案

当会话过期时,重定向到登录页面. [ ^ ]

您的代码的问题在于,它是所有客户端javascript -您尚未在任何地方测试会话,因此您需要回叫服务器才能访问它.

正如我在回答中解释的那样,我真的没有任何必要.您可以通过将网页正确设置为不可缓存来实现网页的正确行为
Please see my answer recently about a similar Session issue

Redirect to login page when the Session is Expired.[^]

The problem with your code is that it''s all client side javascript - you haven''t tested for the session anywhere, you''d need to call back to the server in order to access that.

As I explained in my answer, I really don''t see the need for any of this. You can achieve correct behaviour of web pages by correctly setting pages to be non-cacheable


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

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