The trick is to create a class that keeps it's own sessionstate, like this:
public class CustomerSession
{
private string mName = "";
private string mTelephone = "";
// To enshure unique session key
private static string mGuid = "PlaceGUIDHere";
public string Name
{
get { return mName; }
set { mName = value; }
}
public string Telephone
{
get { return mTelephone; }
set { mTelephone = value; }
}
private CustomerSession() { }
public static CustomerSession GetInstance(HttpSessionState session)
{
CustomerSession o = (CustomerSession)session[mGuid];
if(o == null) {
o = new CustomerSession();
session[mGuid] = o;
}
return o;
}
}
Then you can save data in session like this:
protected void btnSave_Click(object sender, EventArgs e)
{
CustomerSession data = CustomerSession.GetInstance(Session);
data.Name = txtName.Text;
data.Telephone = txtTelephone.Text;
}
I heard about this in .NET Rocks! episode 82 where Richard Hale Shaw where speaking of his way of storing session state in a safe way. It's at about 54 minutes into the podcast episode if you want to check it out for yourself =)