how to timeout the client session in asp.net
I'm looking to include a behavior in the base page that, when the session times out (after say 20 min), makes a call back to the client, erases the session cookie, and redirects the user to a "your session has timed out" page.
Before I start coding, I was wondering if there's a functionality 开发者_运维技巧in the framework that already handles this.
Thanks.
try this
<script language='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 onload=SessionTimeOuts()'>
ASP.NET MembershipProvider should handle this for you
Correct me if I am wrong but ASP.Net is already doing this. All you have to do just send an interval value to the client after each postback or ajax call. And with this interval you will also have to execute a timeout function that says "your session has expired" dialog as @geek mentioned below.
精彩评论