开发者

Can I access sessions in background thread?

开发者_如何转开发How can i access my project sessions in background thread in my c#.net webapplication?

it gives me session value = null.

Any idea?


Threads in the thread pool are managed by the system. These threads are not bound to the current request. Therefore, Session is not available for them.

session lost when multithreading though


You have to be very careful about using background threads with ASP.NET. By the time the thread executes, the "current" request will probably be over. This means you can't access the page, or the request, or anything interesting.


You can't access the session but you could share your data the same way, using: HttpRuntime.Cache

There are a few things to keep in mind though: unlike session, cache do expire. Also the cache is shared between all web users.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜