473,385 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Session Clearing

Hi, I use lots of sessions. I want to clear the unwanted sessions when I
leave a page. I cant use ViewState as it will slow down the pages. Could some
one help me on this?
Jan 28 '08 #1
6 4972
You are only using sessions on a per page basis?
"Geo" <Ge*@discussions.microsoft.comwrote in message
news:6C**********************************@microsof t.com...
Hi, I use lots of sessions. I want to clear the unwanted sessions when I
leave a page. I cant use ViewState as it will slow down the pages. Could
some
one help me on this?

Jan 28 '08 #2
By sessions, do you mean the Session collection?

If so, it's not clear to me why you'd want to clear it when leaving a page
as the only reason to use the Session collection is to store data between
page requests.

But Session items can be removed using one of several methods:

Session.Clear();
Session.RemoveAll();
Session.Remove(itemName); // Removes only the specified item

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Geo" <Ge*@discussions.microsoft.comwrote in message
news:6C**********************************@microsof t.com...
Hi, I use lots of sessions. I want to clear the unwanted sessions when I
leave a page. I cant use ViewState as it will slow down the pages. Could
some
one help me on this?
Jan 28 '08 #3

One of the reasons I wrote this:
http://sholliday.spaces.live.com/blog/cns!A68482B9628A842A!125.entry

was so that I could "un-orphan" items more cleanly.
And do a .Clear() as well.

Ex:

I have a page that shows an EmployeeByDept report.

Ok...I get the data, and cache it.

So while the user is on

employeebydept.aspx
I want the page .. in session.
This allows me to sort, filter the data from session while they're on that
page, and I only hit the db one time.

When they navigate away from employeebydept.aspx page, I want to un-orphan
the data.

I call the

dataStore.Remove( MY_KEY_NAME);

and its gone.

Make sense?

Take a look, its basically a session bases Singleton object....for each
user.

I never code against the Session object directly anymore.

CHeck my blog, I have a Generic version as well, which gives you strong
typing.


"Geo" <Ge*@discussions.microsoft.comwrote in message
news:6C**********************************@microsof t.com...
Hi, I use lots of sessions. I want to clear the unwanted sessions when I
leave a page. I cant use ViewState as it will slow down the pages. Could
some
one help me on this?

Jan 28 '08 #4
Alright, I believe I am not clear here..

Every page has lots of data and i use on an average of 10 sessions a page. I
want to clear them out when I finish using them whether it is within a page
or within pages.

I could use Session.Remove, but I am afraid that I could miss some sessions.
Also where would I be calling these session.remove methods? On Page load?
Since I use menu to navigate - every screen must have these methods?

I am looking for a Page_unload event which fires when the page unloads -
EVEN when the menu is clicked. Page_Unload fires only when the current page
changes but not from the menu..

Geo.
"Jonathan Wood" wrote:
By sessions, do you mean the Session collection?

If so, it's not clear to me why you'd want to clear it when leaving a page
as the only reason to use the Session collection is to store data between
page requests.

But Session items can be removed using one of several methods:

Session.Clear();
Session.RemoveAll();
Session.Remove(itemName); // Removes only the specified item

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Geo" <Ge*@discussions.microsoft.comwrote in message
news:6C**********************************@microsof t.com...
Hi, I use lots of sessions. I want to clear the unwanted sessions when I
leave a page. I cant use ViewState as it will slow down the pages. Could
some
one help me on this?

Jan 28 '08 #5
This doesn't make any sense.

A session represents the time that a visitor arrives at your site to the
time they leave, regardless of what pages they visit in between. To be
creating session variables on a page and then destroying them on that same
page defeats the purpose of session.

If you only need the data on a particular page, just use regular page
variables.

If you really do need to keep data between different pages, consider using
cross-page postbacks, querystrings (if applicable), cookies, a database, or
of course sessions.

But, generally, you don't need to worry about manually clearing the session
values, as they will be dropped when the session times out (normally 20
minutes, but you can bring that number down if you like).

Just curious, why is ViewState not an option?

"Geo" <Ge*@discussions.microsoft.comwrote in message
news:84**********************************@microsof t.com...
Alright, I believe I am not clear here..

Every page has lots of data and i use on an average of 10 sessions a page.
I
want to clear them out when I finish using them whether it is within a
page
or within pages.

I could use Session.Remove, but I am afraid that I could miss some
sessions.
Also where would I be calling these session.remove methods? On Page load?
Since I use menu to navigate - every screen must have these methods?

I am looking for a Page_unload event which fires when the page unloads -
EVEN when the menu is clicked. Page_Unload fires only when the current
page
changes but not from the menu..

Geo.
"Jonathan Wood" wrote:
>By sessions, do you mean the Session collection?

If so, it's not clear to me why you'd want to clear it when leaving a
page
as the only reason to use the Session collection is to store data between
page requests.

But Session items can be removed using one of several methods:

Session.Clear();
Session.RemoveAll();
Session.Remove(itemName); // Removes only the specified item

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Geo" <Ge*@discussions.microsoft.comwrote in message
news:6C**********************************@microso ft.com...
Hi, I use lots of sessions. I want to clear the unwanted sessions when
I
leave a page. I cant use ViewState as it will slow down the pages.
Could
some
one help me on this?


Jan 29 '08 #6
"Geo" <Ge*@discussions.microsoft.comwrote in message
news:84**********************************@microsof t.com...
Every page has lots of data and i use on an average of 10 sessions a page.
I think you're getting confused with nomenclature...

When a user first visits your site, *one* session is created. There is only
*one* session per user, though each session can contain many session
variables...

Is that what you mean...?
I want to clear them out when I finish using them whether it is within a
page
or within pages.
Using session to persist data within a *single* page makes no sense at all -
that's what ViewState is for...

Session exists to allow you to persist data *across* pages...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jan 29 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bonj | last post by:
H I've got the following problem - I need to have an aspx page with two frames, although the question isn't necessarily about the workings of the frames, more session variables... the frames consist...
9
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use -...
4
by: PJ | last post by:
A particular page seems to be having issues with correctly setting Session variables. I am setting a couple of session variables on the Page_Unload event. While stepping through code, the...
1
by: Wee Bubba | last post by:
i have a class. within the constructor for this class it tests if 2 session objects exist and if they dont it creates them. this is a one off deal. The session objects are both Hashtables. ...
10
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much...
6
by: JJ_377 | last post by:
In a "Save and Quit" button on my web app form (aspx), I have the following code that is supposed to clear a session variable (an user id) and redirect to a logon page: Session.Clear()...
3
by: Chris Rathman | last post by:
I'm having problems with the Session variables disappearing between page calls and thought someone might be able to help me find the errors of my ways. The problem surfaces in two different ways:...
6
by: Kermit Piper | last post by:
Hello, I thought this should be easy, but... all I want to do is set the value of this state drop-down based on a session var I'm getting back from a redirect (from the processing page): <%...
2
by: vikram.lakhotia | last post by:
Hi, Yesterday I was discussion with my colleagues about session and a few interesting things popped up. So I thought I would share the same with all. <a href=http://www.vikramlakhotia.com/...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.