tracking sessions

Discussion in 'ASP .Net' started by mike parr, May 6, 2004.

  1. mike parr

    mike parr Guest

    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!
     
    mike parr, May 6, 2004
    #1
    1. Advertising

  2. mike parr

    avnrao Guest

    you can rather use Session_Start method in Global.asax file. have this code
    over there.

    Av.
    "mike parr" <> wrote in message
    news:...
    >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!
     
    avnrao, May 6, 2004
    #2
    1. Advertising

  3. mike parr

    Rick Spiewak Guest

    The "back" button isn't a postback, so you need to prevent duplicates.

    "mike parr" <> wrote in message
    news:...
    > 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!
     
    Rick Spiewak, May 6, 2004
    #3
  4. mike parr

    Patrice Guest

    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" <> a écrit dans le message de
    news:...
    > 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!
     
    Patrice, May 6, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Cox [Microsoft MVP]

    Re: Relationship between IIS Sessions and ASP.NET Sessions?

    Ken Cox [Microsoft MVP], Aug 8, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    5,380
    Luther Miller
    Aug 8, 2003
  2. Andrew Chalk

    Tracking Sessions in a Python CGI app.

    Andrew Chalk, Sep 4, 2003, in forum: Python
    Replies:
    2
    Views:
    410
    Andrew Chalk
    Sep 5, 2003
  3. scottymo
    Replies:
    3
    Views:
    719
    Dominick Baier
    Sep 30, 2006
  4. panda

    tracking sessions

    panda, Oct 25, 2006, in forum: ASP General
    Replies:
    3
    Views:
    116
    Anthony Jones
    Oct 27, 2006
  5. Bookham Measures

    Moving from ASP Sessions to Database Sessions

    Bookham Measures, Jul 23, 2007, in forum: ASP General
    Replies:
    19
    Views:
    579
    Bookham Measures
    Aug 23, 2007
Loading...

Share This Page