473,246 Members | 1,307 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,246 software developers and data experts.

Session Variables - HELP !!

Hi there

I am using several processes within an .asp application that store variables
in to session - typically:

Session("UniqueName") = Value

I am having a hell of a time overwriting the Session value once it has been
stored the first time - namely I can't

I am even following a code example in a book which has a function that
creates a dataset and puts it in Session:

dim ds as dataset.....etc. etc....

Session("Dataset") = ds

A process will then retrieve that dataset and add a row and store the
ammended dataset in to the same Session("Dataset")

Another process then needs to retrieve the ammended DataSet but it is always
the original dataset retrieved and the ammendments are missing ! (This is not
the only occurrance of this problem in my application) - I must be missing
something here - PLEASE HELP ME

I appreciate any input you may have - in the above example if I store the
ammended dataset as Session("Dataset2") the whole process works fine, so I am
confident the code is good - for unavoidable reasons I can not change the
stored dataset name in my working app so this is not a solution for me - and
surely this should work anyway ???

(I have tried Session.Add("Dataset", ds) as an alternative to no avail)

Thanks
Nov 19 '05 #1
2 2265
This should fix it, and clean up your session management too. Sit down and
define exactly what the user's session needs to look like for the
application and create a class that represents that information. Then allow
that class to manage its own lifecycle. Here's an Example....

<Serializable()> Public Class UserSession
Private _shoppingCart as Dataset
Private _birthday as DateTime

Public Property ShoppingCart as Dataset
Get
Return _shoppingCart
Set(value as Dataset)
_shoppingCart = value
End set
End Property

Public Property Birthday() as DateTime
Get
Return _birthday
End Get
Set(Value as DateTime)
_birthday = value
End Set
End Property

'This shared property manages the class's lifecycle for you
Public Shared Readonly Property Current() as UserSession
Get
If System.Web.HttpContext.Current is Nothing is Nothing Then
Return Nothing
If System.Web.HttpContext.Current.Session("UserSessio n") is
Nothing Then _
System.Web.HttpContext.Current.Session("UserSessio n")=new
UserSession()
Return
Ctype(System.Web.HttpContext.Current.Session("User Session"), UserSession)
End Get
End Property
End Class

If you need to interact with your session, Just refer to UserSession.Current

e.g.
txtBirthday.Text = UserSession.Current.Birthday.ToShortDateString
dgCart.DataSource = UserSession.Current.ShoppingCart
UserSession.Current.Birthday = DateTime.Now

This way:
1) Your Session Class Manages its own lifecycle
2) You have a firm image of what your session state, as a whole looks like.
You can avoid sporadic Session variables floating around, bloated session
state, and you don't have to worry about the typos inherent in the
session("StringKeyName") construct.

Hope this helps you out.

"Stuart" <St****@discussions.microsoft.com> wrote in message
news:2B**********************************@microsof t.com...
Hi there

I am using several processes within an .asp application that store variables in to session - typically:

Session("UniqueName") = Value

I am having a hell of a time overwriting the Session value once it has been stored the first time - namely I can't

I am even following a code example in a book which has a function that
creates a dataset and puts it in Session:

dim ds as dataset.....etc. etc....

Session("Dataset") = ds

A process will then retrieve that dataset and add a row and store the
ammended dataset in to the same Session("Dataset")

Another process then needs to retrieve the ammended DataSet but it is always the original dataset retrieved and the ammendments are missing ! (This is not the only occurrance of this problem in my application) - I must be missing
something here - PLEASE HELP ME

I appreciate any input you may have - in the above example if I store the
ammended dataset as Session("Dataset2") the whole process works fine, so I am confident the code is good - for unavoidable reasons I can not change the
stored dataset name in my working app so this is not a solution for me - and surely this should work anyway ???

(I have tried Session.Add("Dataset", ds) as an alternative to no avail)

Thanks

Nov 19 '05 #2
Thanks David - this is a TOP recommendation which I have implemented and
indeed it makes life and code far more straight forward with Session
variables - so thanks very much...
"David Jessee" wrote:
This should fix it, and clean up your session management too. Sit down and
define exactly what the user's session needs to look like for the
application and create a class that represents that information. Then allow
that class to manage its own lifecycle. Here's an Example....

<Serializable()> Public Class UserSession
Private _shoppingCart as Dataset
Private _birthday as DateTime

Public Property ShoppingCart as Dataset
Get
Return _shoppingCart
Set(value as Dataset)
_shoppingCart = value
End set
End Property

Public Property Birthday() as DateTime
Get
Return _birthday
End Get
Set(Value as DateTime)
_birthday = value
End Set
End Property

'This shared property manages the class's lifecycle for you
Public Shared Readonly Property Current() as UserSession
Get
If System.Web.HttpContext.Current is Nothing is Nothing Then
Return Nothing
If System.Web.HttpContext.Current.Session("UserSessio n") is
Nothing Then _
System.Web.HttpContext.Current.Session("UserSessio n")=new
UserSession()
Return
Ctype(System.Web.HttpContext.Current.Session("User Session"), UserSession)
End Get
End Property
End Class

If you need to interact with your session, Just refer to UserSession.Current

e.g.
txtBirthday.Text = UserSession.Current.Birthday.ToShortDateString
dgCart.DataSource = UserSession.Current.ShoppingCart
UserSession.Current.Birthday = DateTime.Now

This way:
1) Your Session Class Manages its own lifecycle
2) You have a firm image of what your session state, as a whole looks like.
You can avoid sporadic Session variables floating around, bloated session
state, and you don't have to worry about the typos inherent in the
session("StringKeyName") construct.

Hope this helps you out.

"Stuart" <St****@discussions.microsoft.com> wrote in message
news:2B**********************************@microsof t.com...
Hi there

I am using several processes within an .asp application that store

variables
in to session - typically:

Session("UniqueName") = Value

I am having a hell of a time overwriting the Session value once it has

been
stored the first time - namely I can't

I am even following a code example in a book which has a function that
creates a dataset and puts it in Session:

dim ds as dataset.....etc. etc....

Session("Dataset") = ds

A process will then retrieve that dataset and add a row and store the
ammended dataset in to the same Session("Dataset")

Another process then needs to retrieve the ammended DataSet but it is

always
the original dataset retrieved and the ammendments are missing ! (This is

not
the only occurrance of this problem in my application) - I must be missing
something here - PLEASE HELP ME

I appreciate any input you may have - in the above example if I store the
ammended dataset as Session("Dataset2") the whole process works fine, so I

am
confident the code is good - for unavoidable reasons I can not change the
stored dataset name in my working app so this is not a solution for me -

and
surely this should work anyway ???

(I have tried Session.Add("Dataset", ds) as an alternative to no avail)

Thanks


Nov 19 '05 #3

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

Similar topics

6
by: Al Jones | last post by:
This is a repost form the vbscript newgroup - if this isn't the appropriate group would you point me toward one that is. Basically, I seem to be losing session data part way though preparing an...
6
by: Lina Manjarres | last post by:
Hello, I have a session variable in a login page. Then I go to a form page where I uses the ProfileID and the UserID. Then I go to a result page where I would like to use the UserID as a filter,...
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...
31
by: Harry Simpson | last post by:
I've come from the old ASP camp where session variables were not used. When i started using ASP.NET in 2001, I started using them again because it was ok from what I'd read. I've been merrily...
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...
3
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have...
3
by: Phillip N Rounds | last post by:
I'm writing a user control which has two states: Active & InActive. I additionally am required that there to be only one active control per page, and all logic has to be contained within the...
18
by: BillE | last post by:
When a user opens a new IE browser window using File-New-Window the integrity of an application which relies on session state is COMPLETELY undermined. Anyone who overlooks the fact that...
26
by: BillE | last post by:
Some ASP.NET applications use Session Variables extensively to maintain state. These should be re-written to use viewstate, hidden fields, querystring, etc. instead. This is because if a user...
12
by: MrHelpMe | last post by:
Hello again all, I've finished my whole application and now I don't like the whole session variables that I am using. I have a form, user fills in info clicks submit and using CDOSYSMail an...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...

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.