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.
Related Posts
- Retrieve Current Module/Controller/Action inside View Script / Layout Script Before I forget to do this again I’m going to make a post on how to get the current Module, Controller, and Action while inside a View Script or Layout Script. Here is the most correct way to do it: Now, here is the incorrect way I attempted to do...
- PHP5.x or PHP6 – Argument for Type-Hinting: Better IDEs I’ve read some posting lately about PHP6, the Meeting Notes by the Developers, etc. that deal with type-hinting, especially scalar type hinting. Here is my reasoning why PHP should allow for more type-hinting scenarios: it allows IDEs to be more powerful. An example would be auto completion. Many times an...