Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
ASP.NET: Accessing the Response object in a Class
From Wiki
Summary: Accessing the Response object in a Class
Need help with ASP.NET? Come and ask a question in our ASP.NET Forum
Whilst I'm not a big fan of this method (I don't think the session should be accessed directly from a class as it is then tied to an ASP.NET project and won't work if you tried to use the class in a windows project for example) you can access the session directly if needed.
For example, let's say we want to return a session variable from a public property in our of our classes. Instead of accession "Session" like we would do in a page, we have to use HttpContext.Current.Session to get a reference to the current session object. So, we can come up with this simple example:
- Public Property GetMySessionValue() As String
- Get
- Return HttpContext.Current.Session("mySessionVariable").ToString
- End Get
- Set(ByVal Value As String)
- HttpContext.Current.Session("mySessionVariable") = Value
- End Set
- End Property
This Hack is part of the ASP.NET Hacks collection



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.