473,569 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Interpret session data from ASPStateTempSes sions

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.





Nov 19 '05 #1
1 6190
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******** *****@TK2MSFTNG P15.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 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.





Nov 19 '05 #2

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

Similar topics

0
1031
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 sessions fine and can get the sessionID. My question is, isit possible to re-load the session into a session object fromanother area. For Example, I...
9
2089
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" sqlConnectionString="data source=myserver;user id=myuser;password=mypw" cookieless="false" timeout="20" /> This seems to work. But we have cases, when users...
2
3777
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
2845
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 and set them to cookieless mode. As well we added Session.Timeout=240 in asp.net-application and saved data into the session. Session-Timeout in...
1
1594
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 field in the ASPStateTempSessions Table and it shows the correct value. What I expect is that when I hit the page after 5 minutes, the Session...
2
3527
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. ---> System.Data.SqlClient.SqlException: General network error. Check your network documentation. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior...
0
255
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 see a new record inserted into ASPStateTempSessions table. However when I attempt to load the data from a session variable, it is always nothing. ...
1
3243
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 would remove the Session from the table. Is their a different method I should use to remove the Session table entry? Is the only way the session...
3
3445
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 mode="SQLServer" sqlConnectionString="Integrated Security=SSPI;data source=localhost" timeout="1" >
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7917
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.