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

Shared Session Data

I'm using sql server session state and wrote a class to wrap current
session. I need to know if what I am doing will result in users
sharing session data.

'----------------------------------
'------- Session Wrapper --------
'-----------------------------------
Imports System.Web.SessionState
Public Class EmployeeSession

Private _session As HttpSessionState

Sub New()
_session = HttpContext.Current.Session
End Sub

Property EmployeeID() As Integer
Get
Return _session("EmployeeID")
End Get
Set(ByVal Value As Integer)
_session("EmployeeID") = Value
End Set
End Property

End Class
'-----------------------------------
'-----------------------------------
'-------- Sub on a web form -------
'-----------------------------------

Private Sub DoSomething
Dim empSession as new EmployeeSession

empSession.EmployeeID=someValue
End Sub

'----------------------------------
Any ideas or help appreciated

Steve

Nov 19 '05 #1
3 1311
No, it will not.
In fact, I would make all the methods in EmployeeSession Shared. So you
don't need to bother instantiating it every time. Then something like this:

Public Shared Property EmployeeID() As Integer
Get
CInt(GetItem("EmployeeID"))
End Get
Set(Value As Integer)
SetItem("EmployeeID",Value)
End Set
End Property

Private Shared Function GetItem(itemName As String) As Object
Return HttpContext.Current.Session(itemName)
End Function

Private Shared Sub SetItem(itemName As String, itemValue As String)
HttpContext.Current.Session(itemName) = itemValue
End Sub

That way you can say EmployeeSession.EmployeeID, without instantiating
anything. Also, all the functionality of how everything is stored, is
actually in GetItem and SetItem, properties call out to that.

And lastly, please turn Option Strict On in your project, and make this the
default. This will save you many hours by catching errors at run time.

"MS ASP.NET" <sb*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I'm using sql server session state and wrote a class to wrap current
session. I need to know if what I am doing will result in users
sharing session data.

'----------------------------------
'------- Session Wrapper --------
'-----------------------------------
Imports System.Web.SessionState
Public Class EmployeeSession

Private _session As HttpSessionState

Sub New()
_session = HttpContext.Current.Session
End Sub

Property EmployeeID() As Integer
Get
Return _session("EmployeeID")
End Get
Set(ByVal Value As Integer)
_session("EmployeeID") = Value
End Set
End Property

End Class
'-----------------------------------
'-----------------------------------
'-------- Sub on a web form -------
'-----------------------------------

Private Sub DoSomething
Dim empSession as new EmployeeSession

empSession.EmployeeID=someValue
End Sub

'----------------------------------
Any ideas or help appreciated

Steve

Nov 19 '05 #2
Beautiful!

Thanks for your help!

Nov 19 '05 #3
No Problem.
Second parameter to SetItem should be an Object, so you can put anything in
there. It was just to give the basic ide anyway...

"MS ASP.NET" <sb*****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Beautiful!

Thanks for your help!

Nov 19 '05 #4

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

Similar topics

1
by: Fredrik Melin | last post by:
Hi, I have a support library with all functionallity I need to access my business application on the web. The problem is that Connection object, User object and some other objects are Shared...
4
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml...
3
by: Philip Tepedino | last post by:
I'm having an odd problem. My website's session state is getting shared between users! This problem only happens when a user tries to access the site from inside our corporate LAN. The user,...
4
by: Shankar Reddy | last post by:
Hi All, Problem: Data is being shared across multiple sessions in ASP.NET! Does anybody come across this kind of situation where session data or view state data is being shared across...
3
by: masoud bayan | last post by:
Hi, We have 3 different web applications on three different websites (and domains). Now we want to make it possible for users to login in each of these applications and can navigate to other...
15
by: Rob Nicholson | last post by:
A consequence of the ASP.NET architecture on IIS has just hit home with a big thud. It's to do with shared variables. Consider a module like this: Public Module Functions Public GlobalName As...
2
by: Ibrahim. | last post by:
Hello, My question is simple. If Session variables were to be assigned a value inside a shared function, does the session data visible to other sessions (Other users). I know the variables...
3
by: tshad | last post by:
I have a .ascx file that I converted to a class. But I am getting the following error: error BC30469: Reference to a non-shared member requires an object reference. The error is for the...
3
by: Jeff | last post by:
....still new to vb.net and vs 2005 web applications. I remain confused about the "shared" variable/table designation and the difference between "public" etc. I wish to place an entire table from...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.