Using Application() variables in non-web classes

  • Thread starter Thread starter Brian Bischof
  • Start date Start date
B

Brian Bischof

Hi All,

I saved a variable to the Application() collection and I can access this
from the aspx.vb code. However, I want to be able to access this variable
from a simple class. I've seen where I can have the class inherit from one
of the web classes, but I don't want to do that just for a simple class that
needs one variable. Currently, I'm making a public property in the class and
setting it during the Application_Start() event. But I don't think this is
the best approach. Is it possible to use the Application() collection from a
simple class?

Thanks,

Brian
 
You should look into:

System.Web.HttpContext.Current.Application

That will give you the application object of the current web request when
the code runs.

HTH,

bill
 
Absolutely...

Add an import entry to the class:
System.Web.HttpContext
Either at the top of your class, or under project
properties.

Then, in your class, you reference the
Session/Application/Server etc objects via:

{System.Web.HttpContext.}Current.
{Application|Session|Server etc}

-----Original Message-----
Hi All,

I saved a variable to the Application() collection and I can access this
from the aspx.vb code. However, I want to be able to access this variable
from a simple class. I've seen where I can have the class inherit from one
of the web classes, but I don't want to do that just for
a simple class that
 
Back
Top