473,473 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Static Class VS. Application State

I have a few variables that need to be accessible throughout my ASP.NET Web
app, across all possible Sessions.

AFAIK, there are two reasonable places to store them:
1. Application state (read the values from Web.config on ApplicationStart()
and then refer to them there).

2. properties of a static class (read values from Web.config when the app
starts, and then refer to them there).

Are there any good reasons to chose one of these approaches over the other?
I have currently implemented via #2, but was just wondering if anyone sees
any problems with that approach.

Thanks!
Nov 19 '05 #1
2 1393
#2. Aside from various other reasons, it will allow you to use that same
class in non web environment.

--
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.mastervb.net/home/ng/foru...t10017013.aspx
http://www.eggheadcafe.com/articles/..._generator.asp

"Smithers" <Ja*********@OnceOver.com> wrote in message
news:OG*************@TK2MSFTNGP12.phx.gbl...
I have a few variables that need to be accessible throughout my ASP.NET Web
app, across all possible Sessions.

AFAIK, there are two reasonable places to store them:
1. Application state (read the values from Web.config on
ApplicationStart() and then refer to them there).

2. properties of a static class (read values from Web.config when the app
starts, and then refer to them there).

Are there any good reasons to chose one of these approaches over the
other? I have currently implemented via #2, but was just wondering if
anyone sees any problems with that approach.

Thanks!

Nov 19 '05 #2
#1 is the standard way to do this kind of thing.

#2 isn't necesarrily bad, but you can encounter rare, hard to debug
threading problems if you're not careful about how you implement this.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Smithers" <Ja*********@OnceOver.com> wrote in message
news:OG*************@TK2MSFTNGP12.phx.gbl...
I have a few variables that need to be accessible throughout my ASP.NET Web
app, across all possible Sessions.

AFAIK, there are two reasonable places to store them:
1. Application state (read the values from Web.config on
ApplicationStart() and then refer to them there).

2. properties of a static class (read values from Web.config when the app
starts, and then refer to them there).

Are there any good reasons to chose one of these approaches over the
other? I have currently implemented via #2, but was just wondering if
anyone sees any problems with that approach.

Thanks!

Nov 19 '05 #3

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

Similar topics

9
by: Simon Harvey | last post by:
Hi all, In my project I have made a number of helper methods static. As I understand it, this will create the problem that multiple threads could access the static method at the same time and...
1
by: Simon Harvey | last post by:
Hi everyone, I have a class that I want to use to store application state information. I was thinking that I would probably want to make all the information static in that class because the...
3
by: Ryan Steckler | last post by:
I found this behavior while trying to implement a singleton class. Below is a somewhat more straight forward example, though admittedly less useful in real life. The basic problem is that when a...
3
by: Dave | last post by:
Hi, Is there a general rule to use 'static' on a class member? It seems uneccessary to have to create an instance of an object just to use it's methods where declaring something as static makes...
7
by: Andrea Williams | last post by:
I would like to be able to create a singleton when using my Error Handling object. It uses a static Instance() method to return the currently activated object. But my question is, since it is...
9
by: craigkenisston | last post by:
Hi, I'm starting my first asp.net application and I decided to put the users preferences in a static class. I thought, the static class would be just seen by current session, but it seems it...
8
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical...
6
by: WebMatrix | last post by:
Is there any performance considerations or any other concerns about having a Class with private constructor and all static functions? One particular function in question creates a few new instances...
12
by: chandu | last post by:
hello, i want to know usage of static methods in a class. is it advantageous or disadvantage to use more static methods in a class. thank u
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
1
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.