Session and Application in a Class

  • Thread starter Thread starter Vik
  • Start date Start date
V

Vik

How can I access the Session and Application objects in some class method?
Currently I pass a page as a parameter to this method just to get these
objects. Is there a better way?

Thanks.
 
You can use the HttpContext class' static property Current. As long as the
class you're writing is called from an asp.net application,
HttpContext.Current contains a reference to the current HTTP request.

For example:

using System.Web;

public class SomeClass
{
public void SomeMethod()
{
int postedFormElements = HttpContext.Current.Request.Form.Count;
}
}

HTH,
Lars-Erik
 
Back
Top