By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,915 Members | 1,327 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,915 IT Pros & Developers. It's quick & easy.

Session.Clear ?

P: n/a
When I log of I do:

HttpContext.Current.Session.Clear()
FormsAuthentication.SignOut()
The problem is that it clears the variables that I set up in my
Session_Start function in my Global.asax file. One of the variables I set
up is:

Session("Start") = DateTime.Now.ToString

This allows me to track the time that the use is in our system. The
Session.Clear() gets rid of it.

Is there a way to do a good way to do a Clear, but have it not touch some of
the variables?

Thanks,

Tom
Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Loop through Session.Keys maybe.
Clint Hill
H3O Software
http://www.h3osoftware.com
tshad wrote:
When I log of I do:

HttpContext.Current.Session.Clear()
FormsAuthentication.SignOut()
The problem is that it clears the variables that I set up in my
Session_Start function in my Global.asax file. One of the variables I set
up is:

Session("Start") = DateTime.Now.ToString

This allows me to track the time that the use is in our system. The
Session.Clear() gets rid of it.

Is there a way to do a good way to do a Clear, but have it not touch some of
the variables?

Thanks,

Tom

Nov 19 '05 #2

P: n/a
There is no method that comes with it that can do this. That's pretty
specific.

Why not write your own ClearSession method, that can delete everything one
by one, provided it is not one of the special session items that you want to
keep.

"tshad" <ts**********@ftsolutions.com> wrote in message
news:ux**************@tk2msftngp13.phx.gbl...
When I log of I do:

HttpContext.Current.Session.Clear()
FormsAuthentication.SignOut()
The problem is that it clears the variables that I set up in my
Session_Start function in my Global.asax file. One of the variables I set
up is:

Session("Start") = DateTime.Now.ToString

This allows me to track the time that the use is in our system. The
Session.Clear() gets rid of it.

Is there a way to do a good way to do a Clear, but have it not touch some
of
the variables?

Thanks,

Tom

Nov 19 '05 #3

P: n/a
Clint Hill wrote:
Loop through Session.Keys maybe.
Clint Hill
H3O Software
http://www.h3osoftware.com
tshad wrote:
When I log of I do:

HttpContext.Current.Session.Clear()
FormsAuthentication.SignOut()
The problem is that it clears the variables that I set up in my
Session_Start function in my Global.asax file. One of the variables I
set
up is:

Session("Start") = DateTime.Now.ToString

This allows me to track the time that the use is in our system. The
Session.Clear() gets rid of it.

Is there a way to do a good way to do a Clear, but have it not touch
some of
the variables?

Thanks,

Tom

This is exactly the solution.
Here is the code:
(This example is for cache but it works the same in Session)

IDictionaryEnumerator CacheEnum = Cache.GetEnumerator();
while (CacheEnum.MoveNext())
{
Cache.Remove(CacheEnum.Key.ToString());
//cacheList.Add(CacheEnum.Key,CacheEnum.Value);
}

--

SevDer
http://www.sevder.com
Nov 19 '05 #4

P: n/a
Since you already know which Session Items have been set,
why don't you *only* remove the ones you want to get rid of,
with Session.Contents.Remove, instead of using Session.Clear() ?

Session.Contents.Remove("ThisSessionVariableIsGone ")
....but the others remain.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"tshad" <ts**********@ftsolutions.com> wrote in message
news:ux**************@tk2msftngp13.phx.gbl...
When I log of I do:

HttpContext.Current.Session.Clear()
FormsAuthentication.SignOut()
The problem is that it clears the variables that I set up in my
Session_Start function in my Global.asax file. One of the variables I set
up is:

Session("Start") = DateTime.Now.ToString

This allows me to track the time that the use is in our system. The
Session.Clear() gets rid of it.

Is there a way to do a good way to do a Clear, but have it not touch some of
the variables?

Thanks,

Tom


Nov 19 '05 #5

P: n/a

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:ud**************@TK2MSFTNGP15.phx.gbl...
Since you already know which Session Items have been set,
why don't you *only* remove the ones you want to get rid of,
with Session.Contents.Remove, instead of using Session.Clear() ?

Session.Contents.Remove("ThisSessionVariableIsGone ")
...but the others remain.


The other thought I had was to save the ones I am interested in keeping, do
the clear and then put them back.

I could loop through, but there could be 30 or more and then I would need to
check each one to see if it was one I wanted to keep. But since I would
obviously need to know which I wanted to keep, why not just save the ones I
want temporarily and then put them back.

Something like:

Dim OldStart = Session("start") 'Keep this as the clear will dump it
HttpContext.Current.Session.Clear()
session("Start") = oldStart 'Put the start time back.

I would think this would be more efficient than 30 or more compares (in the
loop) and then 30 or more removes (less the ones I want to keep). Of
course, I might be wrong here.

Thanks,

Tom
Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"tshad" <ts**********@ftsolutions.com> wrote in message
news:ux**************@tk2msftngp13.phx.gbl...
When I log of I do:

HttpContext.Current.Session.Clear()
FormsAuthentication.SignOut()
The problem is that it clears the variables that I set up in my
Session_Start function in my Global.asax file. One of the variables I
set
up is:

Session("Start") = DateTime.Now.ToString

This allows me to track the time that the use is in our system. The
Session.Clear() gets rid of it.

Is there a way to do a good way to do a Clear, but have it not touch some
of
the variables?

Thanks,

Tom


Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.