Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > tracking sessions

Reply
Thread Tools

tracking sessions

 
 
mike parr
Guest
Posts: n/a
 
      05-06-2004
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



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
avnrao
Guest
Posts: n/a
 
      05-06-2004
you can rather use Session_Start method in Global.asax file. have this code
over there.

Av.
"mike parr" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
 
 
 
Rick Spiewak
Guest
Posts: n/a
 
      05-06-2004
The "back" button isn't a postback, so you need to prevent duplicates.

"mike parr" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      05-06-2004
Doesnt' matter ? You'll just set the value agzain and refresh the timestamp
info.

As a side note, note that the Session object provides a property that allows
to now if the session is newly created. could it be suitable for your needs
?

Patrice


"mike parr" <(E-Mail Removed)> a écrit dans le message de
news:(E-Mail Removed)...
> 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
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tracking sessions panda ASP General 3 10-27-2006 08:34 AM
Cookieless Sessions (Sessions Without Cookies) and Security scottymo ASP .Net Security 3 09-29-2006 11:00 PM
Tracking Someone Tracking Me Edw. Peach Computer Security 4 07-07-2005 05:50 PM
Tracking Sessions in a Python CGI app. Andrew Chalk Python 2 09-05-2003 09:46 PM
Re: Relationship between IIS Sessions and ASP.NET Sessions? Ken Cox [Microsoft MVP] ASP .Net 1 08-08-2003 03:22 PM



Advertisments