Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Shared Session Data

Reply
Thread Tools

Shared Session Data

 
 
MS ASP.NET
Guest
Posts: n/a
 
      05-19-2005
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

 
Reply With Quote
 
 
 
 
Marina
Guest
Posts: n/a
 
      05-19-2005
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" <> wrote in message
news: 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
>



 
Reply With Quote
 
 
 
 
MS ASP.NET
Guest
Posts: n/a
 
      05-19-2005
Beautiful!

Thanks for your help!

 
Reply With Quote
 
Marina
Guest
Posts: n/a
 
      05-19-2005
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" <> wrote in message
news: oups.com...
> Beautiful!
>
> Thanks for your help!
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can i share asp session data with asp.net session data far asl via DotNetMonster.com ASP .Net 3 03-23-2005 05:13 AM
Shared, why not a 'Local Shared' (re: Session and ViewState dislike) ben ASP .Net 3 11-15-2004 03:04 PM
Session data is being shared across multiple sessions Shankar Reddy ASP .Net 4 09-02-2004 06:27 PM
Session data is being shared across multiple sessions Shankar Reddy ASP .Net 4 09-02-2004 06:27 PM
Session data is being shared across multiple sessions Shankar Reddy ASP .Net 0 08-23-2004 06:46 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57