M
mike parr
I need to keep track of users details by session variables and I have
been doing this by putting this code in the default page :
public void Page_Load()
{
if (!(Page.IsPostBack))
{
Session["LiveSession"] = "True";
string strSession;
strSession = "INSERT INTO Session(Time_Stamp) VALUES(GETDATE())
SELECT @@IDENTITY AS 'Identity'";
SqlConnection objConnectionSession = new
SqlConnection(ConfigurationSettings.AppSettings["strConnectServerMcCallu
m"]);
SqlCommand objCommandSession = new SqlCommand(strSession,
objConnectionSession);
// open the connection to the database
objConnectionSession.Open();
// execute the SQL statement, returns 1 row only
Session["SessionID"] = objCommandSession.ExecuteScalar().ToString();
objConnectionSession.Close();
}
So I have a Session ID to identify the user when I am later writing to
my database, and I check if Session["LiveSession"] = true when I load a
new page to check if the session has timed out.
Do I need to prevent the user from clicking Back to this page where I am
setting all this session stuff up, or will this code only ever be
reached on the first load of the page?
Thanks,
Mike
been doing this by putting this code in the default page :
public void Page_Load()
{
if (!(Page.IsPostBack))
{
Session["LiveSession"] = "True";
string strSession;
strSession = "INSERT INTO Session(Time_Stamp) VALUES(GETDATE())
SELECT @@IDENTITY AS 'Identity'";
SqlConnection objConnectionSession = new
SqlConnection(ConfigurationSettings.AppSettings["strConnectServerMcCallu
m"]);
SqlCommand objCommandSession = new SqlCommand(strSession,
objConnectionSession);
// open the connection to the database
objConnectionSession.Open();
// execute the SQL statement, returns 1 row only
Session["SessionID"] = objCommandSession.ExecuteScalar().ToString();
objConnectionSession.Close();
}
So I have a Session ID to identify the user when I am later writing to
my database, and I check if Session["LiveSession"] = true when I load a
new page to check if the session has timed out.
Do I need to prevent the user from clicking Back to this page where I am
setting all this session stuff up, or will this code only ever be
reached on the first load of the page?
Thanks,
Mike