473,386 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Interpret session data from ASPStateTempSessions

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.





Nov 19 '05 #1
1 6162
As the author of that article, the only reason I can think as to why session wasn't available
is that your current session timeout is less than the cache expiration (last touched).

If you set the session timeout to a greater number, you can optionally call Session.Abandon
after your custom code in the cache callback. Thus, you wouldn't really be holding onto
session longer than you currently are.

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net

"Seetha J" <se*****@yahoo.com> wrote in message news:ei*************@TK2MSFTNGP15.phx.gbl...
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.





Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Scott Vercuski via .NET 247 | last post by:
Hello all, I have a question with respect to the ASP Session State. Here's the scenario I have. I've setup the session on our SQLserver in the ASPState.ASPStateTempSessions table. I can seethe...
9
by: Patrick | last post by:
Hello I'm running two Webservers Using ASP.NET. both are running the same ASP.NET Application, with <sessionState mode="SQLServer" stateConnectionString="tcpip=127.0.0.1:42424"...
2
by: Gibson Smith | last post by:
If I am storing session ID in the database, what should be the size? Currently I am using SQL Server 2000 and varchar as my data type. Gibson
5
by: Tim W. | last post by:
Folks. In a B2B Procurement system we've created, we got following Session-Issue: Configuration: We are using IIS 6.0 and added SQL-Based-Sessions in web.config with a timeout of 240 minutes...
1
by: Tejaswi | last post by:
Hello! I have set the Session Timeout to 5 minutes. I login to the Web Page and then wait for 6 minutes. Then I again try to get the page and the Session does not expire. I checked the Expires...
2
by: SethHer | last post by:
error: System.Web.HttpException: Exception of type System.Web.HttpException was thrown. ---> System.Web.HttpException: Unable to connect to SQL Server session database. --->...
0
by: sabrina | last post by:
Hi, I am trying to set my web application to use sql server mode for session state. I have made the change to the web.config and ran InstallPersistSqlState. When the application runs, I can...
1
by: Ed | last post by:
I am trying out SessionState with Mode=SQLServer. I have my code run Session.Abandon, but the session entry in the table ASPStateTempSessions is still there? I was expecting that Session.Abandon...
3
by: Moe Sisko | last post by:
Using dotnet 2.0 sp1, I've got ASP.NET session state working ok in SQLServer mode, but the sessions never seem to expire. e.g if I add a timeout attribute like so : <sessionState...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.