Solved

How to automatically end/logout a session?

Posted on 2004-04-30
4
598 Views
Last Modified: 2010-08-05
How to automatically end a session?
In idea, I have set up in web.config that after 20 minutes of no user action, my ASP NET application will call Logout.aspx and then logout automatically without showing any error aspx page.

In web.config:
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20"/>

In Global.asax.vb:
Private Sub Session_OnEnd(ByVal sender As Object, ByVal e As EventArgs)
        Server.Transfer("Logout.aspx", True)
End Sub

In Logout.aspx:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Server.CreateObject("Session.Management").SessionEnd()
End Sub

But I'm not sure if after 20 minutes of no user action, Logout.aspx will be called. And the statement Server.CreateObject("Session.Management").SessionEnd() gets error!
What would be the correct way of ending session? Thanks!
0
Comment
Question by:IloveClipper
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
esteban_felipe earned 95 total points
ID: 10965416
Hi IloveClipper,

Your code will actually end the session but the Server.Transfer("Logout.aspx",true) won't work. That's because you can't push pages to the client using server side code if the client haven't first requested a page. The correct way to achieve what you're looking for will be a client side javascript that will redirect to another page (logout.aspx in your case) 20 minutes after the current page was rendered.

Esteban Felipe
www.estebanf.com
0
 

Author Comment

by:IloveClipper
ID: 10965529
Esteban,
Does it mean that I have to put that javascript code on every aspx page of my project?
0
 
LVL 12

Expert Comment

by:esteban_felipe
ID: 10965934
you could use a base Page class that register the javascript
0
 

Expert Comment

by:venkat_parupudi
ID: 11150065
cfdsfsdfsdfsdfsd
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question