Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 9th, 2009, 02:27 AM
Authorized User
 
Join Date: Mar 2005
Posts: 36
Thanks: 2
Thanked 1 Time in 1 Post
Default Clearing Sessions - Browser Closing using close(cross mark at top right corner) butt

Hi,
I have SQL server Session Management and I have given time out as 20 in web config file.
I am creating some session objects to keep my datatables in a page. Now I have a situation where in user is closing the browser using cross button. Can I be sure that session will be cleaned up immediately? I guess no. Few questions in this regard are :
1. Is the session will end based on SQL Server Session setting?
2. Will the GC collect the session?
Could anybody please clarify me.

Last edited by abinashpatra; January 9th, 2009 at 02:39 AM..
 
Old January 9th, 2009, 11:03 AM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Call Session.Abandon().
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old January 10th, 2009, 12:37 AM
Authorized User
 
Join Date: Mar 2005
Posts: 36
Thanks: 2
Thanked 1 Time in 1 Post
Default

Dear Lee,
Problem for me is where to call this.
I can open up a small popup in the body unload and clear up all the session, but this will open up a tiny popup which I don't want. Is there any other way to do this?
 
Old January 10th, 2009, 02:31 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Quote:
Originally Posted by abinashpatra View Post
1. Is the session will end based on SQL Server Session setting?
2. Will the GC collect the session?
(1) Yes. At the time specified, 20 minutes after the last activity (if you use the default setting as you said you do).

(2) Yes, at the time that (1) occurs.

************

The problem with trying to do something using <BODY onUnload=> or <BODY onBeforeUnload=> is that you have to be VERY careful that your code is aware of when the unload is happening because the user closed the browser (or goes to another site or or or) instead of an unload that happens when you are moving to another page on your own site or even when your ASP.NET page is doing a POSTBACK. Yes, EACH change of page WILL invoke the UNLOAD. Yes, if you are very careful with your JavaScript code, you can figure out what kind of UNLOAD is happening. But it's not an easy task.

Unless this is really really important to you, I would suggest just letting .NET do the session close automatically, at the end of the 20 minutes.
 
Old January 10th, 2009, 02:43 AM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Usually, you would call this from a logout button. But, I see I did not read your question closely, as you were asking about what to do if the user closes the browser.

In that case, the session would remain alive to listen for requests until the time between requests exceeds the timeout value.

May I ask, why do you need to explicitly clear the session anyway?

If you are not storing sensitive information in Session, then it should not matter.

If you are storing sensitive information in Session, then you should be using SSL, to eliminate the possibility that the Sessiion could be hijacked.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old January 10th, 2009, 10:47 PM
Authorized User
 
Join Date: Mar 2005
Posts: 36
Thanks: 2
Thanked 1 Time in 1 Post
Default

Dear All,
Thanks for your responses.
To respond to Lee's Question,
1. Yes we are using the SSL. And there is no harm in waiting for the session to be cleared on its own.
2. I am interested in clearing the session because this will keep eating up the Server's memory(Web Server,IIS). We would be doing performance testing on this application and when load is applied and lets say session is not cleared then and there it would eat up the server memory to a greater extent.
 
Old January 10th, 2009, 11:30 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Thankfully, memory is not all that expensive nowadays.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old January 11th, 2009, 11:14 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

> I am interested in clearing the session because this will keep eating up the Server's memory

Ummm... In your very first post, you said

Quote:
I have SQL server Session Management
So explain to me how you will eat up *MEMORY* when the session management is done in the *DATABASE*????

No, I do *not* think you will notice any memory being used.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Close Child window automatically on closing parent vikas67k C# 1 August 26th, 2008 02:00 AM
Browser close when screen saver close Rehanrana Pro VB 6 1 April 7th, 2008 03:09 AM
HOW TO CLOSED BUTTON x IN TOP CORNER dayash_r_prasad ASP.NET 1.0 and 1.1 Basics 5 June 20th, 2007 04:46 AM
Cross browser compatibility hussainm BOOK: Professional Ajax ISBN: 978-0-471-77778-6 3 December 4th, 2006 07:34 AM
Repositioning Top Left Corner of a Page in print dontknowmuch Java GUI 0 September 30th, 2005 12:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.