468,309 Members | 1,078 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,309 developers. It's quick & easy.

Session Variables in Static Objects

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

Mar 21 '06 #1
2 2064
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/
<ja***@instantecommerce.co.uk> wrote in message
news:11**********************@j33g2000cwa.googlegr 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

Mar 21 '06 #2
Thanks very much Karl

Mar 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bonj | last post: by
2 posts views Thread by adam | last post: by
4 posts views Thread by John Kraft | last post: by
9 posts views Thread by William LaMartin | last post: by
6 posts views Thread by Just D | last post: by
15 posts views Thread by Jason | last post: by
2 posts views Thread by Markus Prediger | last post: by
9 posts views Thread by Randy | last post: by
5 posts views Thread by Sean | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.