Solved

How to automatically end/logout a session?

Posted on 2004-04-30
4
585 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
Comment Utility
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
Comment Utility
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
Comment Utility
you could use a base Page class that register the javascript
0
 

Expert Comment

by:venkat_parupudi
Comment Utility
cfdsfsdfsdfsdfsd
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now