Last post May 23, 2011 11:09 AM by Glasgow
May 20, 2011 11:23 AM|Glasgow|LINK
I am storing some information in a Session variable. I have a Structure that contains a number of separate items including login data and shopping basket data. At the end of the Page_LoadComplete event I store the structure as follows:
Current.Session("SessionPool") = Spl
And I retrieve it at the start of the Page_Load event as follows:
Spl = Current.Session("SessionPool")
Throughout my logic I refer to items within the structure such as spl.loginrow (a datarow) and spl.basket (a datatable).
I am testing the (remote) web site from two independent PCs. I change the quantity of items for one line in the shopping basket on one PC then, on the other PC, I refresh the basket and, hey presto, it reflects changes I have made on the first PC.
This suggests to me that the session variable is being shared across all sessions somehow - i.e. it is being managed at an application level. Does this make any sense? Any suggestions about what kind of dumb mistake I could have made here?
May 20, 2011 11:52 AM|smcoxon|LINK
How is Spl defined? Is it shared? I.e. is the Loginrow or basket table created as shared?
May 20, 2011 11:55 AM|karthic_85|LINK
session cant be shared across application,spl should have static content in it...
May 20, 2011 12:20 PM|Glasgow|LINK
Thanks for the replies. It is declared (in a module) like this
Public Structure SessionPool
Public RowLogin As DataRow
Public TblBsk As DataTable
Public BskStatus As BasketStatus
Public Administrator As Boolean
Public AdminUser As String
Public Spl As SessionPool
so it's not explicitly shared. Any thoughts?
May 20, 2011 12:52 PM|roopeshreddy|LINK
May be the structure is inside a static class, like the below code,
public static class DataHandler
public struct MyStruct
public string name;
If yes, then that is the problem causing you.
Hope it helps u...
May 20, 2011 12:58 PM|Glasgow|LINK
Thanks. It's inside a module:
Public Module MscLib
Is that OK?
May 20, 2011 01:25 PM|karthic_85|LINK
Modules counterparts to static classes.
When your class is designed solely for helper functions.you define it as Module
You cannot have variables or objects that changes per user....
May 20, 2011 01:29 PM|smcoxon|LINK
Have you tried:
Public Spl As New SessionPool
to create a new instatnce of sessionPool each time a user opens this page
May 20, 2011 01:53 PM|Glasgow|LINK
Thanks. Oh dear!
If I define, retrieve and update the structure within master page code behind then pass the structure as a parameter ByRef through to the routines in the module, is that a possible solution?
May 20, 2011 04:55 PM|Glasgow|LINK
Sorry smcoxon, I was replying to previous post. I had considered the 'new' approach. I will try.
May 23, 2011 11:09 AM|Glasgow|LINK
I bit the bullet and removed all my modules. I'm not happy with my final solution which effectively resulted in me putting lots of code that I felt logically belonged in separate files in a single code-behind module but it was the quickest solution and I
am under some time pressure. I hope to come back to it at some tage and implement a more elegant solution.