Session Clearing
am 28.01.2008 22:46:03 von GeoHi, 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?
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?
You are only using sessions on a per page basis?
"Geo"
news:6C49734E-0F26-4492-A01A-C6877125002F@microsoft.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?
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"
news:6C49734E-0F26-4492-A01A-C6877125002F@microsoft.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?
Many of them are on per page basis. I have so much data and so I dont want to
use ViewState. I save DataSets and Class objects.
"Scott M." wrote:
> You are only using sessions on a per page basis?
>
>
> "Geo"
> news:6C49734E-0F26-4492-A01A-C6877125002F@microsoft.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?
>
>
>
One of the reasons I wrote this:
http://sholliday.spaces.live.com/blog/cns!A68482B9628A842A!1 25.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"
news:6C49734E-0F26-4492-A01A-C6877125002F@microsoft.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?
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"
> news:6C49734E-0F26-4492-A01A-C6877125002F@microsoft.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?
>
>
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"
news:845483E5-76DC-49A7-9F3E-0206E07542FB@microsoft.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"
>> news:6C49734E-0F26-4492-A01A-C6877125002F@microsoft.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?
>>
>>
"Geo"
news:845483E5-76DC-49A7-9F3E-0206E07542FB@microsoft.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