A
adam
Having spent nearly 2 years in win forms land the inevitable request came
for me to "do some web pages".
So being new to this bit of .net and having had a look around I can't see
where the best way to store session data.
1) use the (string)Session["MyValue"] approach
Obviously bad for maintenance, readability etc.
2) have a typed MySession object with static properties for each value I
want to store
class MySession
{
public static string MyValue
{
get{return (string)Session["MyValue"];}
set{Session["MyValue"] = value;}
}
}
3) have a single session object that has all properties on it
class MySession
{
string m_MyValue = "";
public static MySession GetSession(HttpSession sess)
{
MySession ret = sess["MySession"] as MySession;
if (ret==null)
{
ret = new MySession();
sess["MySession"] = ret;
}
return ret;
}
public string MyValue
{
get{return m_MyValue ;}
set{m_MyValue = value;}
}
}
4) do as for 3 but for each Page (or a base Page) for page specific
information
all session key strings can of course be const or an enum.
What is the recommended approach (ignore scaling to multiple servers for
now)?
adam
for me to "do some web pages".
So being new to this bit of .net and having had a look around I can't see
where the best way to store session data.
1) use the (string)Session["MyValue"] approach
Obviously bad for maintenance, readability etc.
2) have a typed MySession object with static properties for each value I
want to store
class MySession
{
public static string MyValue
{
get{return (string)Session["MyValue"];}
set{Session["MyValue"] = value;}
}
}
3) have a single session object that has all properties on it
class MySession
{
string m_MyValue = "";
public static MySession GetSession(HttpSession sess)
{
MySession ret = sess["MySession"] as MySession;
if (ret==null)
{
ret = new MySession();
sess["MySession"] = ret;
}
return ret;
}
public string MyValue
{
get{return m_MyValue ;}
set{m_MyValue = value;}
}
}
4) do as for 3 but for each Page (or a base Page) for page specific
information
all session key strings can of course be const or an enum.
What is the recommended approach (ignore scaling to multiple servers for
now)?
adam