Reputation: 7
Is it byte inside the session or data will be converted into the string after writing? if yes I think I can take it like this:
var res = Encoding.UTF8.GetBytes(Session["session_state"]);
or can I take it "as is" without converting into the byte array? like:
var res = Session["session_state"] as bytes[]; // or smth. like that
Upvotes: 0
Views: 5981
Reputation: 700690
The data isn't converted. If the session object is serialized (depending on how it is stored), then it is deserialized before you get access to it again.
Just cast the value to a byte array:
var res = Session["session_state"] as byte[];
or:
var res = (byte[])Session["session_state"];
Side note: A byte array can't reliably be converted to a string using UTF-8 encoding. UTF-8 is used the other way around, i.e. converting a string to bytes and then back. To make a string from bytes you would rather use something like base64.
Upvotes: 3
Reputation: 5056
You will always get what you stored in the session regardless of the mode you are using for the session state (inproc, state server, ...)
So the answer will be
var res = Session["session_state"] as byte[];
Upvotes: 0