Newbie - HttpApplicationState question.

  • Thread starter Thread starter Zalek Bloom
  • Start date Start date
Z

Zalek Bloom

I want to display how many times my Web application was used. I want
to add a counter to HttpApplicationState:
HttpApplicationState a = new HttpApplicationState();
a.Add("Counter", 1);

My question - I did not see a constructor for HttpApplicationState.

And if I put the above code in the method Application_Start() in
Global.asax.cs - will object "a" will be visible in all my classes?

Thanks,

Zalek
 
I want to display how many times my Web application was used. I want
to add a counter to HttpApplicationState:
HttpApplicationState a = new HttpApplicationState();
a.Add("Counter", 1);

My question - I did not see a constructor for HttpApplicationState.

And if I put the above code in the method Application_Start() in
Global.asax.cs - will object "a" will be visible in all my classes?

No.

But if you write:

Application["Counter"] = 0;

in Application_Start and:

Application["Counter"] = (int)Application["Counter"] + 1;

in Session_Start then you pages can get the value with:

Application["Counter"]

Arne
 
Back
Top