Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Session vars vs. HttpContext.Current.User

Reply
Thread Tools

Session vars vs. HttpContext.Current.User

 
 
Jason
Guest
Posts: n/a
 
      02-10-2005
Currently, I am storing information about the currently logged on user
in Session variables that are stored in SQL. However, I am using
role-based security, so I am storing custom roles in a GenericPrincipal
object that I attached to Context.User. My question is this:

Can I create a new class, ExtendedPrincipal for instance, and simply
inherit System.Security.Principal and store all of the information
currently stored in Session variables in this new object? Is this
responsible/efficient/appropriate?

Thanks in advance!
Jason

 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      02-10-2005
Since the Session is specific to the User, there is no need to add this
level of complexity.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Jason" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Currently, I am storing information about the currently logged on user
> in Session variables that are stored in SQL. However, I am using
> role-based security, so I am storing custom roles in a GenericPrincipal
> object that I attached to Context.User. My question is this:
>
> Can I create a new class, ExtendedPrincipal for instance, and simply
> inherit System.Security.Principal and store all of the information
> currently stored in Session variables in this new object? Is this
> responsible/efficient/appropriate?
>
> Thanks in advance!
> Jason
>



 
Reply With Quote
 
 
 
 
Jason
Guest
Posts: n/a
 
      02-10-2005
Thanks. I was under the impression that using session variables was
yesterdays technology and that this information was handled better by a
new .NET way. This is good though. Now I don't have to go back and
make alot of changes.

 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      02-10-2005
Something you could do though would be to create a class with shared numbers
that exposes these session variables as properties.
This way you'll get strong typing and intellisense on those values plus you
don't need to change at once as under the hood there are still stored as
session variables.

Patrice

--

"Jason" <(E-Mail Removed)> a écrit dans le message de
news:(E-Mail Removed) ups.com...
> Thanks. I was under the impression that using session variables was
> yesterdays technology and that this information was handled better by a
> new .NET way. This is good though. Now I don't have to go back and
> make alot of changes.
>



 
Reply With Quote
 
Jason
Guest
Posts: n/a
 
      02-10-2005
Never thought about that! But I am unfamiliar with "shared numbers" or
how to get a list of "choices" to be displayed when you are trying to
set a property of a class.

 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      02-10-2005
What language are you using ? The keyword is Shared in VB.NET and static in
C#.
It allows to have a member that is the same for all objects of a class.
Under the hood it uses the user session to store the value.

Having a list is done using an Enumeration (Enum in both languages if I
remember)...

Actually I didn't thought about that either. Saw this suggestion once in
this group...

Patrice



--

"Jason" <(E-Mail Removed)> a écrit dans le message de
news:(E-Mail Removed) ups.com...
> Never thought about that! But I am unfamiliar with "shared numbers" or
> how to get a list of "choices" to be displayed when you are trying to
> set a property of a class.
>



 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      02-10-2005
> Under the hood it uses the user session to store the value.

Static objects are stored in the application heap, not Session.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Patrice" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> What language are you using ? The keyword is Shared in VB.NET and static
> in
> C#.
> It allows to have a member that is the same for all objects of a class.
> Under the hood it uses the user session to store the value.
>
> Having a list is done using an Enumeration (Enum in both languages if I
> remember)...
>
> Actually I didn't thought about that either. Saw this suggestion once in
> this group...
>
> Patrice
>
>
>
> --
>
> "Jason" <(E-Mail Removed)> a écrit dans le message de
> news:(E-Mail Removed) ups.com...
>> Never thought about that! But I am unfamiliar with "shared numbers" or
>> how to get a list of "choices" to be displayed when you are trying to
>> set a property of a class.
>>

>
>



 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      02-10-2005
"Patrice" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> don't need to change at once as under the hood there are still stored as
> session variables.


No they aren't! They're stored as application variables.


 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      02-10-2005
> No they aren't! They're stored as application variables.

Afraid not. Static objects are stored in the application heap. Always have
been. Always will be. That is, after all, the definition of "static."

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Mark Rae" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Patrice" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> don't need to change at once as under the hood there are still stored as
>> session variables.

>
> No they aren't! They're stored as application variables.
>



 
Reply With Quote
 
=?Utf-8?B?SiBTYXd5ZXIgW01pY3Jvc29mdF0=?=
Guest
Posts: n/a
 
      02-10-2005
Kevin ...
Technically, you are correct ... if these static members are merely
accessors for private variables. For example:
Public Class MySessionVars
Private Shared _myInt As Integer
Public Shared Property MyInt() As Integer
Get
Return _myInt
End Get
Set(ByVal Value As Integer)
_myInt = Value
End Set
End Property
End ClassThis would store the variables in the heap *and* have the same
values for every user! Not desirable in this situation.
Doing this, however, would be different:
Public Class MySessionVars
Public Shared Property MyInt() As Integer
Get
Return CInt(HttpContext.Current.Session("MyInt"))
End Get
Set(ByVal Value As Integer)
HttpContext.Current.Session("MyInt") = Value
End Set
End Property
End Class
In this case, the static property is merely a wrapper around the current
HttpContext's Session object. Note that this will *crash and burn* if not in
an ASP.NET environment! It is the second method that I think Patrice was
referring to ... and I would agree with Patrice on this practice. It's a
nice layer to abstract the details of the Session, providing flexibility on
storage location of the information, providing intellisense and strong
typing. Many Good Things(tm).
Jason ... you'd add the above class (or something like it) to your project
as a class file in the web solution. From there, you would refer to it like
so:
Dim myInt as Integer = MySessionVars.MyInt

You do not have to create an instance of the class to access static/Shared
members of the type.


"Kevin Spencer" wrote:

> > Under the hood it uses the user session to store the value.

>
> Static objects are stored in the application heap, not Session.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> ..Net Developer
> Neither a follower nor a lender be.
>
> "Patrice" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > What language are you using ? The keyword is Shared in VB.NET and static
> > in
> > C#.
> > It allows to have a member that is the same for all objects of a class.
> > Under the hood it uses the user session to store the value.
> >
> > Having a list is done using an Enumeration (Enum in both languages if I
> > remember)...
> >
> > Actually I didn't thought about that either. Saw this suggestion once in
> > this group...
> >
> > Patrice
> >
> >
> >
> > --
> >
> > "Jason" <(E-Mail Removed)> a écrit dans le message de
> > news:(E-Mail Removed) ups.com...
> >> Never thought about that! But I am unfamiliar with "shared numbers" or
> >> how to get a list of "choices" to be displayed when you are trying to
> >> set a property of a class.
> >>

> >
> >

>
>
>

 
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
Use self.vars in class.method(parameters, self.vars) caccolangrifata Python 18 07-22-2011 10:22 PM
How do I declare global vars or class vars in Python ? Linuxguy123 Python 7 02-20-2009 06:45 PM
app vars and cache vars Jon ASP .Net 3 12-14-2004 08:52 PM
Re: Session vars Natty Gur ASP .Net 0 06-25-2003 02:59 PM
Re: Session vars Justin SB ASP .Net 0 06-25-2003 02:09 PM



Advertisments