如何获取会话数据具有了HttpContext.Current,通过的SessionID [英] How to get Session Data with out having HttpContext.Current, by SessionID

查看:461
本文介绍了如何获取会话数据具有了HttpContext.Current,通过的SessionID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找找到一种方法阅读和会话数据写入,但与出具有的HttpContext 。电流

I am searching to find a way to read and write on session data but with out having the HttpContext. Current.

为什么我赢了这样做吗?因为我想做出一些动作与用户会话页面后已接近和卸载。

Why I won to do that ? because I wish to make some action with the user Session after the page have been close and unloaded.

例如,一个用户负载,看到一个页面,然后我创建一个线程来做出一些动作,让用户去。这个线程内我喜欢读会话数据,但在这种情况下,的HttpContext 。目前不存在了。

For example, a user load and see a page, then I create a thread to make some action and let user go. Inside this thread I like to read the session data, but in this case HttpContext . Current is not exist any more.

那么,有没有办法读会话数据只知道会话ID。

So is there a way to read Session Data knowing just the session id.

我在我的会话存储在SQL Server里面,我看到他们。上表ASPStateTempSessions它的存在:)

如何阅读离线和操纵他们?

感谢您先进的。

推荐答案

还是不太清楚为什么你可能想这样做的的你可能实际上并不需要做对Session_End中()。在这一点上,它可能为时已晚,为您的会话数据的工作,反正(我以前这个阅读一些文章)。什么可能是一个更好的解决办法是实际尝试在会话数据的当你的应用程序其实有上下文

Still not quite clear why you might want to do that but you might not actually need to do it on Session_End(). At that point, it may be too late for you to work with the session data anyway (I've read some articles before about this). What might be a better solution is to actually attempt to work on the session data when your application actually has the context.

例如:

有什么能阻止你的应用程序在后台创建一个新的线程异步请求(甚至是不同的应用程序,如Windows服务,例如),当您需要的特定的会话变量被更新或已定。这样,你的应用程序将能够访问当前HttpContext以及所有的会话数据。

There's nothing to stop your application creating an asynchronous request on a new thread in the background (or even a different application, such as a Windows Service, for instance) when the specific session variable that you want is updated or has been set. This way, your application will be able to access the current HttpContext as well as all of the session data.

不知道这会有所帮助,但它是值得一试;)

Not sure if this helps, but it was worth a shot ;)

理查德。

这篇关于如何获取会话数据具有了HttpContext.Current,通过的SessionID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆