Reputation: 21
HttpContext.Current is null on a callback or when on a different thead. How do i get around this. I have seen few examples where they say
LocalDataStoreSlot slot = Thread.GetNamedDataSlot("SlotName");
return (HttpContext)Thread.GetData(slot);
It doesnt work.. and honestly it didnt make much sense.
Any suggestions?
Upvotes: 2
Views: 1615
Reputation: 8595
You'd need to pass the HttpContext object into what ever you start the thread with:
e.g.
var task = Task.Factory.StartNew(
state =>
{
var context = (HttpContext)state;
//do your stuff here
},
HttpContext.Current);
Martin
Upvotes: 4