How to get Session Data with out having HttpContext.Current, by SessionID

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.

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.

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

I store my session inside an SQL server, and I see them. its there on table ASPStateTempSessions šŸ™‚

How can I read them ā€œofflineā€ and manipulate them ?

Thank you in advanced.,

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

For example:

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 šŸ˜‰

Richard.

Method 2

I may be a little late but…
Today I found about the:
System.Web.HttpRuntime.Cache

I know is not the same that a session but I think it’s much better alternative that db.
Regards.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x