I've stored some strings in web storage (session and/or local), and am wondering if it is possible to check for such stored strings on page load or init on the server-side (asp.net c# in my case)... So, for example, I will know not to re-fetch data from the db and use what is already resident in the browser from the last page load.
Asked
Active
Viewed 2.3k times
12
-
Would a cookie work for you, or do you need to store a larger volume of data? – Zachary May 07 '12 at 20:44
-
Are the values stored in local storage or server-side session? – James Johnson May 07 '12 at 21:12
1 Answers
16
No, that's not possible. sessionStorage
lives on the client. If you want to access it on the server you will have to write javascript that reads the value, puts it in a hidden field so that it is sent to the server. Or javascript that will read the value from the storage and redirect to the server passing it as query string parameter. There's absolutely no way for the server accessing directly this storage. That's one of the drawbacks of sessionStorage vs cookies.

Darin Dimitrov
- 1,023,142
- 271
- 3,287
- 2,928
-
Hmmm that makes sense, though your hidden field idea would solve my particular problem, actually. Thanks! – brnwdrng May 07 '12 at 20:48
-
Couldn't he just check whether the value exists in session on `Page_Load` and fetch from the DB if not? – James Johnson May 07 '12 at 21:04
-
2