Session and Application in a Class

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.
 
L

Lars-Erik Aabech

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
 

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