Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am trying to use thread for a method in my asp.net application. But in thread method its giving HttpContext.Current as null. Is there any solution for this.

In pageload :
C#
Thread t1 = new Thread(new ThreadStart(populateProfile));
 t1.Start();
In populateProfile method HttpContext is null.

Thanks,
Posted
Updated 30-Oct-13 3:53am
v2

Check the below link which handles the same issue.

http://odetocode.com/articles/112.aspx[^]

Hope this helps
 
Share this answer
 
Comments
Mada Naga Sankar 31-Oct-13 2:42am    
Its working but HttpContext.Session is showing as null. I am unable to access session values which are assigned in Main thread. Is there anything to include.
JoCodes 31-Oct-13 3:29am    
Can you show how and where you are assigning the session in mainthread? May be i ll try to replicate the issue check
Mada Naga Sankar 31-Oct-13 3:33am    
In login page :
Session["EmpData"] = dt;

After login master page will be excuted

In masterpage:
protected void Page_Load(object sender, EventArgs e)
{
populateProfile();
}

private void populateProfile()
{
DataTable dt = bl.getEmployeeTypes(0, Convert.ToInt32(GlobalMethods.getSessionValue("EmpData", "CompanyId")));

}

public static object getSessionValue(string sessionName, string valueName)
{
object value = null;
DataTable dt = new DataTable();
if (HttpContext.Current != null)
{
dt = (DataTable)HttpContext.Current.Session[sessionName];
if (dt.Rows.Count > 0)
{
value = dt.Rows[0][valueName];
}
}
return value;
}

Session is null in getSessionValue method
JoCodes 31-Oct-13 3:57am    
Have you tried the context.Session["sessionName"] instead of context.current.session["sessionName"] along with the modification provided in the solution link
Mada Naga Sankar 31-Oct-13 6:24am    
There is no Session property in HttpContext.
 
Share this answer
 
Comments
Mada Naga Sankar 31-Oct-13 2:42am    
Its working but HttpContext.Session is showing as null. I am unable to access session values which are assigned in Main thread. Is there anything to include.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900