S
Seetha J
I work on a website where users can apply for different types of loans. Depending on the type of loan we store various sets of data in Session state which is maintained in SQL Server. If the user stops in the middle of loan application process I want to capture whatever data was in the session and store it in our backoffice systems for non-repudiation purposes.
In the past we have been doing it on session end but after we moved to SQL Server Session state, session_onend doesnt get fired. I tried using the expiry of Application Cache as suggested in http://www.eggheadcafe.com/articles/20030416.asp but couldnt get hold of Session object in the Callback function.
Is there a way to get hold of Session data directly from ASPStateTempSessions table? When I tried to deserialize whatever data that comes out of SessionItemShort column I keep getting the following error.
{"Binary stream does not contain a valid BinaryHeader, 101 possible causes, invalid stream or object version change between serialization and deserialization. " }
Here is the code snippet
-----------------------
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select SessionID, Created, Expires, SessionItemShort From ASPStateTempSessions";
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
sessionId = dr.GetString(0);
byte[] sessionData =(byte[]) dr[3];
int ArraySize = sessionData.GetUpperBound(0);
FileStream fs = new FileStream(@"C:\Temp\TestingSession.log", FileMode.OpenOrCreate, FileAccess.ReadWrite);
fs.Write(sessionData, 0,ArraySize);
fs.Close();
BinaryFormatter bf = new BinaryFormatter();
Object obj = bf.Deserialize(fs); //FAILS HERE
...
}
------------------
Any help you can provide is greatly appreciated.
Thanks
Seetha.
In the past we have been doing it on session end but after we moved to SQL Server Session state, session_onend doesnt get fired. I tried using the expiry of Application Cache as suggested in http://www.eggheadcafe.com/articles/20030416.asp but couldnt get hold of Session object in the Callback function.
Is there a way to get hold of Session data directly from ASPStateTempSessions table? When I tried to deserialize whatever data that comes out of SessionItemShort column I keep getting the following error.
{"Binary stream does not contain a valid BinaryHeader, 101 possible causes, invalid stream or object version change between serialization and deserialization. " }
Here is the code snippet
-----------------------
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select SessionID, Created, Expires, SessionItemShort From ASPStateTempSessions";
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
sessionId = dr.GetString(0);
byte[] sessionData =(byte[]) dr[3];
int ArraySize = sessionData.GetUpperBound(0);
FileStream fs = new FileStream(@"C:\Temp\TestingSession.log", FileMode.OpenOrCreate, FileAccess.ReadWrite);
fs.Write(sessionData, 0,ArraySize);
fs.Close();
BinaryFormatter bf = new BinaryFormatter();
Object obj = bf.Deserialize(fs); //FAILS HERE
...
}
------------------
Any help you can provide is greatly appreciated.
Thanks
Seetha.