473,657 Members | 2,499 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session Variables and Static Variables

I have found it very easy to have a Helper class that has static
members which access Session Variables. For example:

public class HelperClass
{
public static doCustomer CurrentCustomer
{
get
{
if(HttpContext. Current.Session["Current_Custom er"] == null)
CurrentCustomer = new doCustomer();

return (doCustomer)
HttpContext.Cur rent.Session["Current_Custom er"];
}
set
{
HttpContext.Cur rent.Session["Current_Custom er"] = value;
}
}
}

Is this thread safe? Will each user of the Application still have his
own instance of doCustomer, even though it is accessed via an
Application Wide static member? What is the best practice regarding
Thread Safety, Session Management and Static Members?

Thanks

Mar 23 '06 #1
1 1616
Anybody?

Mar 26 '06 #2

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

Similar topics

4
42020
by: Wayne | last post by:
Hi, I'm new to .NET and have a question about the use of static variables vs. session variables in a web form in C#. Instead of using a session variable to hold a string to persist during datagrid paging. Can I use a static variable? Also, if I use a static variable is that variable shared by everyone that brings up the aspx page? Ex, if 4 people are viewing the aspx page is an instance of the static variable created for each of the...
9
2448
by: William LaMartin | last post by:
I have a problem, mentioned here before, of Session and Application variables disappearing at one site but not at others or on my development computer. The problem is illustrated by an example at http://www.lamartin.com/dotnet/sessiontestset.aspx, were I set Session, Application and Cache variables on the first page and then on the second page view them as the second page is refreshed every five seconds. Before 10 refreshes, the...
6
1264
by: Just D | last post by:
Hi, How slowly is to work with these objects - Application and Session ? Is it much better to create a huge project or some static library and place all variables/constants there instead of many Session objects? When I removed some of Session objects and replaced by another approaches I got an illusion that application started working significantly faster? Is it true?
8
7302
by: Joe Abou Jaoude | last post by:
hi, I have a web app with forms authentication and a timeout session of 20 mins for security reasons. I recently added a feature that allows users (if they want to) to automatically log in (without entering username and password) using the cookies. Now in this case the 20 mins session timeout has no meaning anymore so I m thinking to make the timeout infinite in this case only. my question is, if i do this, and then a user used the...
1
3762
by: aliendolphin | last post by:
I'm having a strange problem possibly with Session variables for one user being accessed by another. I use a static utility class with static methods which get and set certain Session variables. For Example: public static string UserEmail { get { return HttpContext.Current.Session; } set { HttpContext.Current.Session = value; }
15
2513
by: Jason | last post by:
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...
9
3183
by: Randy | last post by:
Hello, I'm having a strange problem. I've got a .NET web app which uses Session variables. Sometime, not all the time, they get cross threaded...that is...one user will have another user's Session variable(s) data assigned to them. I can't figure out why. I've read that other people are having this problem too but I haven't found a resolution yet. Can someone please tell me how I might go about fixing this? Thanks
5
548
by: Sean | last post by:
Problem with sessions I have created an application without concern for sessions. As it turns out I think that might be my undoing. What I have: I have an online quiz. I don’t need to know users or save any data. If the application crashes or user exits the program they should simply start again. Pretty basic. All interactions are stored in an array (not much going on to save to a
1
2006
by: nicepg | last post by:
Hi, i m new in C#, and i m trying to prgramm a calculator program in web application. My program work very well using a static variables but i need to change these variables to session variables.. my static variables are:
0
8397
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6167
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2731
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.