ASP .NET Accessing Session, Request, Response, etc from within a Class

I remember it took me forever to figure this out and the headache before learning this that it caused. Because .NET is strongly typed you are unable to access the Session, Request, or Response (and many other Http/Web object) from within a class library like you can writing in a code-behind file or on the page itself. I battled for weeks (I almost think months) trying to find ways of passing information between my pages and class library, when I finally found the answer:

HttpContext.Current.Session
HttpContext.Current.Response
HttpContext
.Current.Request

Thats it. No special magic, just use the HttpContext.Current Object within a class library that is being used within the context of a website. Once I found that, it made life so much easier, and if you are reading this, I hope it makes your life easier too.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close