Hi danal,
In my opinion, it depends on how you invoke the corresponding method which defined in the separate class file. If the invoked method is running in the same thread of Page_Load, the HttpContext.Current shouldn’t be null. For example, the following code works on my machine.
protected void Page_Load(object sender, EventArgs e)
{
Session["sessionid"] = "01233210";
Class1 c1 = new Class1();
Response.Write(c1.GetSessionID());
}
***************** App_Code\Class1.cs *****************
public string GetSessionID()
{
return HttpContext.Current.Session["sessionid"].ToString();
}
If that method is running in the different thread, you should pass a reference like “naimulah” said. For more informatin, please refer to the following link. Hope it is helpful to you.
Working With HttpContext.Current
http://www.odetocode.com/Articles/112.aspx