473,399 Members | 2,858 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,399 software developers and data experts.

Session.Clear ?

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
5 22127
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
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
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: JezB | last post by:
I want to clear some specific Session variables when the user closes a page. On my page I have a "return to ..." button which navigates back to the parent page from which it was invoked - under 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. ...
0
by: dummy_2600 | last post by:
I have an app I'm a trying to roll out to production in which Session.Clear() doesn't seem to be working for me. Basically we have multiple forms that make up a registration process. At the end...
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()...
4
by: Hugo Flores | last post by:
Hi all, I noticed that there are three methods that can remove session variables Session.Clear() Session.RemoveAll() Session.Abandon() Now my question as is stated on the subject, what is...
1
by: Nathan Sokalski | last post by:
Is there a difference between Session.Clear() and Session.RemoveAll()? The descriptions and documentation pages seem to say exactly the same thing, but I am assuming there must be some reason for...
2
by: Nathan Sokalski | last post by:
I have an application that is using Session state. On one page, I use the Session.Add() method to create the Key/Value pair for the first time. I am then sent to another page using...
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/...
6
by: =?Utf-8?B?R2Vv?= | last post by:
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?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.