If I am using session out proc to SQL Server, it stores session object as serialized to item column which is of VarBinary
type. How do I read data back from session database?
2 Answers
Why not just accession the Session Object by keys / collection as usual ?
Session[key]
The Session storage in Sql server is abstracted, you do not need to use session objects in a different way depending on the storage (memory, sql, custom,...)

- 304
- 1
- 6
-
I need to access session objects based on session IDs. For example one user logged in now and has session stored. Then later on that user's subsequent visits I want to retrieve session values from past visits. – rocky Dec 06 '16 at 17:53
-
OK, there is a way to deserialize the session data from DB, see at bottom. BUt it is imho not the good, way, you should instead persist the data you need to access later in a profile, or watever custom table... I am not the same to return this advice http://stackoverflow.com/questions/23527727/serialization-and-deserialization-of-session-data And ok, if you insist ;-) Here is something that should help you read that evil data http://stackoverflow.com/questions/967497/asp-net-sessionstate-using-sql-server-is-the-data-encrypted – Luc Debliquis Dec 06 '16 at 19:15
From your comments on another response:
I need to access session objects based on session IDs. For example one user logged in now and has session stored.
This isn't the way to do this. Session data is supposed to be temporary. When the user drops off, there should be no expectation that the session state provider will be hanging on to any related information. For this data, you're actually aiming to persist it beyond a single session, which is out-of-scope for the session provider. If you want to persist it, make some tables in the database, and find some way to tie the data in the tables to user ids.

- 4,326
- 1
- 14
- 25