Reputation: 390
I am making async call to a method where I want to use the HttpContext to get and set the session variable. But the HttpContext is showing null while I am usign it. So How I can use HttpContext?
Code:
public void SessionsFetchAllWatchNowAsync()
{
string aaa = Convert.ToString(HttpContext.Current.Session["UserID"]);
}
protected void Page_Load(object sender, EventArgs e)
{
Session[Utility.UserID] = 0;
Action<StartPage> notifyTask = null;
notifyTask = new Action<StartPage>((o) => new StartPage().SessionsFetchAllWatchNowAsync());
if (notifyTask != null)
notifyTask.BeginInvoke(null, null, null);
}
Thanks,
Dalvir
Upvotes: 0
Views: 673
Reputation: 19175
The HttpContext.Current
is set on the thread, which means you will have to pass it in to your Async method in order to use it as the thread that is handling your async method is not the thread that ASP.NET created to handle your request.
Upvotes: 1