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 ASPStateTempSes sions table? When I tried to deserialize whatever data that comes out of SessionItemShor t 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.CreateComm and();
cmd.CommandType = CommandType.Tex t;
cmd.CommandText = "Select SessionID, Created, Expires, SessionItemShor t From ASPStateTempSes sions";
conn.Open();
SqlDataReader dr = cmd.ExecuteRead er();
while (dr.Read())
{
sessionId = dr.GetString(0) ;
byte[] sessionData =(byte[]) dr[3];
int ArraySize = sessionData.Get UpperBound(0);
FileStream fs = new FileStream(@"C: \Temp\TestingSe ssion.log", FileMode.OpenOr Create, FileAccess.Read Write);
fs.Write(sessio nData, 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.