Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to automatically end/logout a session?

Posted on 2004-04-30
4
603 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…

837 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