Access Application object from class

  • Thread starter Thread starter Cliff Harris
  • Start date Start date
C

Cliff Harris

I have a utilities class in my ASP.Net application that encapsulates
functions that I use often. I would like to use this class to access some
object that I have acces to on a page, like Request, Response, and
Application... is there any way for me to access these without having to
pass them in a parameters to my functions?

Thanks,
-Cliff
 
if you don't want them as parameters, put them in the class constructor as a
parameter. When your class instantiates, you save references to these
objects. You should realize from here that saving references to intrinsic
ASP.NET objects is not a good idea at all. I'd stick with passing parameters
if I were you.
 
the best way is:

1) derive a class from Page
2) add member function, property, etc... to this class
3) derive all your WebForm from this page

Enjoy.
Brun
 
I guess I forgot to mention a key part of this... this class has nothing but
static members... I never instantiate it....
From the sound of things, it looks like I'd be wise just passing things in
as parameters...

Thanks for the help,
-Cliff

Alvin Bruney said:
if you don't want them as parameters, put them in the class constructor as a
parameter. When your class instantiates, you save references to these
objects. You should realize from here that saving references to intrinsic
ASP.NET objects is not a good idea at all. I'd stick with passing parameters
if I were you.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
Cliff Harris said:
I have a utilities class in my ASP.Net application that encapsulates
functions that I use often. I would like to use this class to access some
object that I have acces to on a page, like Request, Response, and
Application... is there any way for me to access these without having to
pass them in a parameters to my functions?

Thanks,
-Cliff
 
You can access it like,

httpcontext.Current.session or httpcontext.current.request
 
Back
Top