Click here to Skip to main content
15,903,856 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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="/KB/answers/login.aspx"
//any page where you want the redirection
}

</script>

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

Pls. help to resolve this issue.

Regards,
Ganesh.S
Posted

1 solution

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
 
Share this answer
 
Comments
thatraja 24-Jun-11 6:58am    
You beat me to it, 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900