Using Application() variables in non-web classes

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
 
W

William F. Robertson, Jr.

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
 
D

David Waz...

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
 

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

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,205
Latest member
ElwoodDurh

Latest Threads

Top