Newbie - HttpApplicationState question.

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
 
A

Arne Vajhøj

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
 

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

Top