i have created on web application in Asp.net 4.0 using C#.
i have implemented session in asp pages but i want to access same session data in my class files.
i have searched regarding this, and then i used
HttpContext.Current.Session["something"]
but it is always throwing NullException.
I am calling this method from page load of aspx page.
Thanks in advance....

shashiPosted May 22, 2015, 7:40 AM
KalaiPosted Feb 17, 2014, 5:06 AM
webpage.aspx.cs
===============
protected void Page_Load(object sender, EventArgs e)
{
Session["SessionName"] = "SessionVal";
Sample.testClass obj = new Sample.testClass();
Response.Write(obj.getSession());
}
testClass.cs
===============
public string getSession()
{
if (HttpContext.Current.Session["SessionName"] != null)
{
string sessionID = HttpContext.Current.Session["SessionName"].ToString();
return sessionID;
}
else
{
return "null";
}
}