HttpApplicationState data being lost

M

mnowosad

We have an ASP.NET 2.0 web site, running on IIS version 6.0, Windows 2003
server. On the Application_Start event of the Global.asax.cs, we load
configuration values to the HttpApplicationState dictionary, to be used
throughout by all web site pages, on a read-only fashion.

The problem we are experiencing is that, after running for some hours, the
values of the HttpApplicationState are lost. Our code never assumes there is
a possibility that the golbal data is not there, so it crashes with a
NullReferenceException exception.

So for instance, we have this line of code in the Global.asax.cs:

protected void Application_Start(Object sender, EventArgs e)
{
Application["SiteName"] = " Our web site";
}

And we have this kind of code in our ASP.NET pages.

string siteName = Application["SiteName"];

I know that if you are using the ASP.NET Cache object, you are supposed to
check if the data is still there, since it could have already been scavenged.

But I expected the HttpApplicationState not to have this issue, so our code
would never need to check if data was still there.

I thought the only time HttpApplicationState data would be reset would be
when the web site Application Domain was shut down (either due to ASP.NET
worker process reset or IIS reset).

But in this case, I was expecting the Application_Start event to be
triggered again upon the first request after the Application Domain shut
down, so the data would be loaded again to the HttpApplicationState
dictionary.

Is there any circumstance where HttpApplicationState dictionary entry may be
reset or scavenged during the lifetime of ASP.NET Application Domain, like it
happens with the Cache entries?
 
G

Guest

you can make a static class

class X{
static public string SiteName{
get{
if(Application["SiteName"]==null)
Application["SiteName"] = " Our web site";
return Application["SiteName"] ;
}
}
}

in this case ,if the app/host doesn't reset. Application["SiteName"] will
be load once.as same as in application_start,and it's not load the data at
the host start up,but you use it first
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top