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


KalaiRank #8,005 · 230 reputationPosted Feb 17, 2014, 12:06 AM EST
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";
}
}
shashi193 reputationPosted May 22, 2015, 3:40 AM EDT