473,698 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Static object in Global.asax vs Application State

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 differences in the way both the objects are
handled by IIS.
Are both objects stored in different memory spaces?
I can access both the objects in my web page.

I will be grateful if some one can help me understand the difference.

Regards
Vishwanathan
Nov 19 '05 #1
8 4862
Hello
I think both object have same scope.

bhawin13

Nov 19 '05 #2
On Tue, 5 Jul 2005 20:17:02 -0700, Vishwanathan Raman
<Vi************ ***@discussions .microsoft.com> wrote:
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 differences in the way both the objects are
handled by IIS.
The Application object is basically a hashtable - it stores object
references that you can retrieve with a key value. The Application
object also has some thread safety built-in, whereas a static member
does not.

IIS doesn't know what is happening inside the .NET runtime.
Are both objects stored in different memory spaces?
What do you mean by memory space?
Both objects will live inside the memory space for your application
domain.
I can access both the objects in my web page.

I will be grateful if some one can help me understand the difference.

Regards
Vishwanathan


--
Scott
http://www.OdeToCode.com/blogs/scott/
Nov 19 '05 #3
I'm not sur what is it you call "Applicatio n State". What I can say is that a
static variable in the Global.asax file will be shared by the whole ASPNET
application, but there are many instances of the Global class running in the
ASPNET application. Each of them serves one request at a time, but they are
different instances. Could you provide a code sample ?

Regards
François

"Vishwanath an Raman" wrote:
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 differences in the way both the objects are
handled by IIS.
Are both objects stored in different memory spaces?
I can access both the objects in my web page.

I will be grateful if some one can help me understand the difference.

Regards
Vishwanathan

Nov 19 '05 #4
Hi!

I think you'd find out a lot if you check out this page:
http://msdn.microsoft.com/library/en...asp?frame=true

Also, you might get better performance if you use the HttpContext.Cac he
object instead of the Application.Con tents object.. (Although you'd use some
more memory when the application gets a lot of users)
You find information about both on the link above. :)

HTH,
Lars-Erik

"Vishwanath an Raman" <Vi************ ***@discussions .microsoft.com> wrote in
message news:94******** *************** ***********@mic rosoft.com...
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 differences in the way both the objects are
handled by IIS.
Are both objects stored in different memory spaces?
I can access both the objects in my web page.

I will be grateful if some one can help me understand the difference.

Regards
Vishwanathan

Nov 19 '05 #5
I am facing a problem with the Application State.It expires but I found that
static objects in Global.asax do not expire.I wanted a technical claification
if they were maintained in different mem spaces.

"Lars-Erik Aabech" wrote:
Hi!

I think you'd find out a lot if you check out this page:
http://msdn.microsoft.com/library/en...asp?frame=true

Also, you might get better performance if you use the HttpContext.Cac he
object instead of the Application.Con tents object.. (Although you'd use some
more memory when the application gets a lot of users)
You find information about both on the link above. :)

HTH,
Lars-Erik

"Vishwanath an Raman" <Vi************ ***@discussions .microsoft.com> wrote in
message news:94******** *************** ***********@mic rosoft.com...
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 differences in the way both the objects are
handled by IIS.
Are both objects stored in different memory spaces?
I can access both the objects in my web page.

I will be grateful if some one can help me understand the difference.

Regards
Vishwanathan


Nov 19 '05 #6
Static objects in Global.asax as for any class are created when the class is
first accessed after the application domain has been created, eg when the
first page is accessed after the application started. They are discarded and
recreated if the application domain is recreated (this happens when the
ASPNET application restarts, for example if you have changed your web.config
or if the worker process restarts).

If I read the documentation for HttpApplication State, it says that one and
only one HttpApplication State object is created per ASPNET application, and
it is created when a page is first accessed. For me, this is the exact same
thing as a static variable in Global.asax. So, for me, both static variables
in Global.asax and HttpApplication State are static singletons that reside
inside the application domain of your ASPNET application.

I think that if it looks like HttpApplication State expires, it may be
because your worker process is recycled (it can happen when it outgrows a
memory limit set in the config file, or lives for longer than a time
specified in the config file), but then again, in this case, your static
variables are recreated too.

Don't forget that since both these variables are static, they are shared by
all instances, and need to be locked before any access (read or write). When
do you create the object you put into the HttpApplication State ? When do you
create the static object in Global.asax ? I think the solution to your
problem lies here. If you provide the source code, maybe I will be able to
sort it out.

Hope this Helps

François

"Vishwanath an Raman" wrote:
I am facing a problem with the Application State.It expires but I found that
static objects in Global.asax do not expire.I wanted a technical claification
if they were maintained in different mem spaces.

"Lars-Erik Aabech" wrote:
Hi!

I think you'd find out a lot if you check out this page:
http://msdn.microsoft.com/library/en...asp?frame=true

Also, you might get better performance if you use the HttpContext.Cac he
object instead of the Application.Con tents object.. (Although you'd use some
more memory when the application gets a lot of users)
You find information about both on the link above. :)

HTH,
Lars-Erik

"Vishwanath an Raman" <Vi************ ***@discussions .microsoft.com> wrote in
message news:94******** *************** ***********@mic rosoft.com...
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 differences in the way both the objects are
handled by IIS.
Are both objects stored in different memory spaces?
I can access both the objects in my web page.

I will be grateful if some one can help me understand the difference.

Regards
Vishwanathan


Nov 19 '05 #7
Francois:
Thanks for the insight.I create both the objects in Global.asax file.
eg

public static DataSet DataDictionaryD s = new DataSet();

private DataSet pvtDataDictiona ryDs = new DataSet();

Application["pvtDataDiction aryDs "]= pvtDataDictiona ryDs ;

pvtDataDictiona ryDs =null;

I find that the one in Application State expires and the static remains
active.


"François Lemaire" wrote:
Static objects in Global.asax as for any class are created when the class is
first accessed after the application domain has been created, eg when the
first page is accessed after the application started. They are discarded and
recreated if the application domain is recreated (this happens when the
ASPNET application restarts, for example if you have changed your web.config
or if the worker process restarts).

If I read the documentation for HttpApplication State, it says that one and
only one HttpApplication State object is created per ASPNET application, and
it is created when a page is first accessed. For me, this is the exact same
thing as a static variable in Global.asax. So, for me, both static variables
in Global.asax and HttpApplication State are static singletons that reside
inside the application domain of your ASPNET application.

I think that if it looks like HttpApplication State expires, it may be
because your worker process is recycled (it can happen when it outgrows a
memory limit set in the config file, or lives for longer than a time
specified in the config file), but then again, in this case, your static
variables are recreated too.

Don't forget that since both these variables are static, they are shared by
all instances, and need to be locked before any access (read or write). When
do you create the object you put into the HttpApplication State ? When do you
create the static object in Global.asax ? I think the solution to your
problem lies here. If you provide the source code, maybe I will be able to
sort it out.

Hope this Helps

François

"Vishwanath an Raman" wrote:
I am facing a problem with the Application State.It expires but I found that
static objects in Global.asax do not expire.I wanted a technical claification
if they were maintained in different mem spaces.

"Lars-Erik Aabech" wrote:
Hi!

I think you'd find out a lot if you check out this page:
http://msdn.microsoft.com/library/en...asp?frame=true

Also, you might get better performance if you use the HttpContext.Cac he
object instead of the Application.Con tents object.. (Although you'd use some
more memory when the application gets a lot of users)
You find information about both on the link above. :)

HTH,
Lars-Erik

"Vishwanath an Raman" <Vi************ ***@discussions .microsoft.com> wrote in
message news:94******** *************** ***********@mic rosoft.com...
> 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 differences in the way both the objects are
> handled by IIS.
> Are both objects stored in different memory spaces?
> I can access both the objects in my web page.
>
> I will be grateful if some one can help me understand the difference.
>
> Regards
> Vishwanathan

Nov 19 '05 #8
I'd say it depends on the time you call :
Application["pvtDataDiction aryDs "]= pvtDataDictiona ryDs ;
If you call it in the Global.asax constructor, then each time an Global.asax
object is created, it is replaced (and if you have multiple users at the same
time, it can be often). If you call it in Application_Sta rt, it will be
created only when the first HttpApplication is created, thus only once per
application domain creation. I don't think it's a good idea for the
pvtDataDictiona ryDs object to be an instance member of the Global.asax class
; it should not be garbage collected when the Global.asax object is, since it
is referenced in your HttpApplication State object, but who knows, maybe the
link between your object and the HttpApplication State object is a weak
reference, not valid for the garbage collector.

Try the following :

protected void Application_Sta rt(Object sender, EventArgs e) {
DataSet pvtDataDictiona ryDs = new DataSet();
// Load it
Application.Loc k();
Application["pvtDataDiction aryDs"]= pvtDataDictiona ryDs ;
Application.Unl ock();
}

and see what happens... If the object expires, it means that all objects put
into HttpApplication State that are not referenced outside it end up garbage
collected ! I would call that a bug...

"Vishwanath an Raman" wrote:
Francois:
Thanks for the insight.I create both the objects in Global.asax file.
eg

public static DataSet DataDictionaryD s = new DataSet();

private DataSet pvtDataDictiona ryDs = new DataSet();

Application["pvtDataDiction aryDs "]= pvtDataDictiona ryDs ;

pvtDataDictiona ryDs =null;

I find that the one in Application State expires and the static remains
active.


"François Lemaire" wrote:
Static objects in Global.asax as for any class are created when the class is
first accessed after the application domain has been created, eg when the
first page is accessed after the application started. They are discarded and
recreated if the application domain is recreated (this happens when the
ASPNET application restarts, for example if you have changed your web.config
or if the worker process restarts).

If I read the documentation for HttpApplication State, it says that one and
only one HttpApplication State object is created per ASPNET application, and
it is created when a page is first accessed. For me, this is the exact same
thing as a static variable in Global.asax. So, for me, both static variables
in Global.asax and HttpApplication State are static singletons that reside
inside the application domain of your ASPNET application.

I think that if it looks like HttpApplication State expires, it may be
because your worker process is recycled (it can happen when it outgrows a
memory limit set in the config file, or lives for longer than a time
specified in the config file), but then again, in this case, your static
variables are recreated too.

Don't forget that since both these variables are static, they are shared by
all instances, and need to be locked before any access (read or write). When
do you create the object you put into the HttpApplication State ? When do you
create the static object in Global.asax ? I think the solution to your
problem lies here. If you provide the source code, maybe I will be able to
sort it out.

Hope this Helps

François

"Vishwanath an Raman" wrote:
I am facing a problem with the Application State.It expires but I found that
static objects in Global.asax do not expire.I wanted a technical claification
if they were maintained in different mem spaces.

"Lars-Erik Aabech" wrote:

> Hi!
>
> I think you'd find out a lot if you check out this page:
> http://msdn.microsoft.com/library/en...asp?frame=true
>
> Also, you might get better performance if you use the HttpContext.Cac he
> object instead of the Application.Con tents object.. (Although you'd use some
> more memory when the application gets a lot of users)
> You find information about both on the link above. :)
>
> HTH,
> Lars-Erik
>
> "Vishwanath an Raman" <Vi************ ***@discussions .microsoft.com> wrote in
> message news:94******** *************** ***********@mic rosoft.com...
> > 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 differences in the way both the objects are
> > handled by IIS.
> > Are both objects stored in different memory spaces?
> > I can access both the objects in my web page.
> >
> > I will be grateful if some one can help me understand the difference.
> >
> > Regards
> > Vishwanathan
>
>
>

Nov 19 '05 #9

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

Similar topics

25
5158
by: Sahil Malik [MVP] | last post by:
So here's a rather simple question. Say in an ASP.NET application, I wish to share common constants as static variables in global.asax (I know there's web.config bla bla .. but lets just say I wanna use global.asax) --- Would you declare your static var as --- public static int x ;
3
7179
by: Faisal | last post by:
Hi. I'm in the process of moving an application from ASP to ASP.NET, & I'm writing in VB, using VS.NET. I'm new to the .NET framework & have a basic question regarding static objects defined in global.asax. In the global.asax file I want to declare some static objects (like an ADODB.Connection, an ADODB.Recordset, a Scripting.FileSystemObject...), and so I've done so using object tags. For example I have:
7
1545
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 static, it is shared between users on a web site? That I would not like since each user needs to have their own instance. Does anyone know the behavior of an object that is create and returned through a static method with ASP.NET? If the Singleton...
8
6833
by: Simone Chiaretta | last post by:
I've a very strange behaveour related to a website we built: from times to times, something should happen on the server, and all static variables inside the web application, both defined inside aspx code-behind and in business logic (C# classes used by the aspx) lose their value. I cannot reproduce this on our development server, so I cannot understand what the cause of all this is. We are using asp.net 1.1 with IIS6 on win2003.
5
2006
by: Pross | last post by:
I've got an ASP.NET application and I need some information on every page like the user's name as well as a collection listing which sections of the application the user has access to. I could store the user name in a regular session variable but the collection varies in size based on the user and could grow in the future as the application grows. I don't want to keep going back to the database for this info every time because it's needed...
15
2467
by: randyr | last post by:
I am developing an asp.net app based on a previous asp application. in the asp applications global.asa file I had several <object id="id" runat="server" scope="scope" class="comclass"> tags for objects that the app used to speed up some global level data access and functionality. I have recoded the class libraries in .net and would like to acomplish the same functionality in asp.net.
2
5203
by: Nathan Sokalski | last post by:
I would like to access variables and functions that I declare in the Global.asax.vb file. However, I am having trouble doing that. What does the declaration have to look like in the Global.asax.vb file, and what would I do to access it? (I am using VB.NET for my code) Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
1
4469
by: romeo_a_casiple | last post by:
I'm looking to create an static object that has application scope and be able to access that static object from my web service. I understand there are two ways to do this : 1) use the object tag in the global.asax, such as: <object id="objObject" runat="server" class="TestApplication.MyClass" scope="Application" />
6
2390
by: depalau | last post by:
I'm running into some issues on maintaining a static variable across the lifetime of a web service and I was wondering if anyone could help. Background: We have developed a C#/1.1 web service running on IIS 5/6 that interfaces with a 3rd party DLL referenced by using the DLLImport attribute. Interacting with this 3rd party software through this dll requires an
0
8597
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9148
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
9012
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
8884
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
8855
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
6515
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
5857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4358
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...
3
1992
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.