I want to access HttpContext.Current in my asp.net application within
Task.Factory.Start(() =>{ //HttpContext.Current is null here });
How can I fix this error?
Task.Factory.Start will fire up a new Thread and because the HttpContext.Context is local to a thread it won't be automaticly copied to the new Thread, so you need to pass it by hand:
Task.Factory.Start
Thread
HttpContext.Context
var task = Task.Factory.StartNew( state => { var context = (HttpContext) state; //use context }, HttpContext.Current);
1.4m articles
1.4m replys
5 comments
57.0k users