Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Session Variables in Static Objects

Reply
Thread Tools

Session Variables in Static Objects

 
 
james@instantecommerce.co.uk
Guest
Posts: n/a
 
      03-21-2006
Hi

I am considering storing my session variables within one static object
with session scope. The static object will be a class with accessor
functions to get and set the equivalent session variables stored as
member variables. This will allow strong typing. Apart from the
problems of multithreading, are there any performance overheards of
which I should be aware?

Thanks

James

 
Reply With Quote
 
 
 
 
Karl Seguin [MVP]
Guest
Posts: n/a
 
      03-21-2006
The way this is normally accomplished is via something like:

public class User
{
private int _userId;
public int UserId { get { return _userId; } set { _userId = value;} }

private User(){}

public static User GetCurrentUser()
{
get
{
if (HttContext.Current != null &&
HttpContext.Current.Session["User"] != null)
{
return (User)HttContext.Current.Session["User"];
}
//throw an error? return an anonymous user?
}
}
}

This avoids multithreadng issues, and doesn't have any performance
drawbacks.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hi
>
> I am considering storing my session variables within one static object
> with session scope. The static object will be a class with accessor
> functions to get and set the equivalent session variables stored as
> member variables. This will allow strong typing. Apart from the
> problems of multithreading, are there any performance overheards of
> which I should be aware?
>
> Thanks
>
> James
>



 
Reply With Quote
 
 
 
 
Webmills
Guest
Posts: n/a
 
      03-21-2006
Thanks very much Karl

 
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
destructors for static and non static pointer-to-objects gorda C++ 5 03-07-2010 10:57 AM
Re: Order of destruction of static members and static objects Victor Bazarov C++ 11 12-09-2009 08:54 AM
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
Session Variables and Static Variables cobus.lombard@gmail.com ASP .Net 1 03-26-2006 11:05 AM
Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'. Mike Larkin ASP .Net 1 05-23-2005 12:33 PM



Advertisments