|
Subject:
|
Accessing Strongly Typed Session Data
|
|
Posted By:
|
Woodman
|
Post Date:
|
3/8/2007 11:12:12 AM
|
I have your Professional ASP.NET 2.0 book. Very nice. I am implementing a StateServer to manage session data. I used your samples in the book as a model, but all data stored was string data. My implementation stores int data. Everything has compiled, and I can assign int values to the Session data, but I can't seem to format the syntax appropriately to extract it. The following forms give "Specified cast not valid":
int foo = (int)Session["openproject"]; or int foo = Convert.Int32(Session["openproject"].ToString());
I have implemented a serializable class with private "int" variables for the session object. Help!
Tom
|
|
Reply By:
|
Woodman
|
Reply Date:
|
3/8/2007 6:13:01 PM
|
Here is the class definition...
[Serializable] public class Project { public int projectid;
public Project() { // // TODO: Add constructor logic here // }
public override string ToString() { return String.Format("Project Object: {0:c}}", projectid); }
}
Here is the get/set implemented within the System.Web.UI.Page subclass...
public Project OpenProject { get { return (Project)Session[OPENPROJECT]; } set { Session[OPENPROJECT] = value; } }
|
|
Reply By:
|
Woodman
|
Reply Date:
|
3/9/2007 3:42:07 PM
|
Nevermind. Found the problem. I'm stupid...
this.OpenProject.projectid
|