简体   繁体   English

我可以在后台线程中访问会话吗?

[英]Can I access sessions in background thread?

How can i access my project sessions in background thread in my c#.net webapplication? 如何在c#.net webapplication中的后台线程中访问我的项目会话?

it gives me session value = null. 它给了我session值= 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. 在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 您无法访问会话,但可以使用以下方式共享数据: 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. 此外,缓存在所有Web用户之间共享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM