Accessing Application in New Class

G

Guest

I am writing a a Web Form where I am making calls to a separate class which performs several routines I use on several pages. The routines all require access to the Request, Response, Application, or Session object. On the normal page I can access these objects but I can't seem to get these objects from another class unless I specifically pass in the the objects to the routine

I would like to be able to access the class, and on initialization it would automatically have access to these objects. I keep getting an object not defined

Is there a sample out there that I can view
 
T

Teemu Keiski

Guaranteed that the class is used in HTTP context (called by Page or
controls etc), you can access the HttpContext by using:

System.Web.HttpContext.Current

Again say Request or Response:
======================
System.Web.HttpContext.Current.Request.xxxx
System.Web.HttpContext.Current.Response.xxxx

and so on. You can import System.Web namespace as well provide straight
reference to HttpContext.Current to make staements bit shorter if typing
starts to fed up.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

I am writing a a Web Form where I am making calls to a separate class which
performs several routines I use on several pages. The routines all require
access to the Request, Response, Application, or Session object. On the
normal page I can access these objects but I can't seem to get these objects
from another class unless I specifically pass in the the objects to the
routine.

I would like to be able to access the class, and on initialization it would
automatically have access to these objects. I keep getting an object not
defined.

Is there a sample out there that I can view.
 
G

Guest

Thank you. Yes it was in HTTP context and I can now access all the objects

I did Import the objects

Regards
 

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