Logging in Session Variables Issue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JP SIngh

    Logging in Session Variables Issue

    Hi All

    We have an ASP application which tracks holidays for our employees. When the
    user logs in we store thier username in a session variable and use that
    variable when displaying and adding data to the access database. The
    username is the primary key for the database table.

    strUsername = request.form("U serName")
    set RS = server.createob ject("ADODB.rec ordset")
    MySql="select * from empprofile where empname ='" & strUserName & "'"
    RS.Open MYSql, CONN_STRING

    if not RS.eof then
    session("UserNa me") = strUserName
    session("Email" ) = RS("Email")
    response.redire ct("displayholi days.asp")
    end if

    on the display holidays page I run a query like

    Select * from HolidayRequest where Username = '" & session("Userna me") & "'"

    to display the holiday records for that employee.

    I have two questions.

    1. Is it a good practice to store the username in a session variable to keep
    track of who is logged in?

    2. Sometimes when a user is logged in for too long without any activity the
    session variable clears and when adding or displaying records it gives an
    error. What I would like to do is somehow keep a track and if at all the
    session variable expires for it to display a message that "You have been
    logged off" please login again but logging in again should take the user
    back to the page which logged them out.

    Many thanks for your help in advance.


  • Dominic Marsat

    #2
    Re: Logging in Session Variables Issue

    > 1. Is it a good practice to store the username in a session variable to
    keep[color=blue]
    > track of who is logged in?[/color]

    You don't really have a choice because the HTTP protocol that you
    use to browse is stateless, therefore, each request for a page is
    completely independant of earlier requests.

    Using a session variable is fine. I think it's only really an issue
    for very busy web servers.

    [color=blue]
    > 2. Sometimes when a user is logged in for too long without any activity[/color]
    the[color=blue]
    > session variable clears and when adding or displaying records it gives an
    > error. What I would like to do is somehow keep a track and if at all the
    > session variable expires for it to display a message that "You have been
    > logged off" please login again but logging in again should take the user
    > back to the page which logged them out.
    >[/color]

    Just check for when the variable contains nothing

    i.e.

    <%
    If Session("user_n ame")="" Then
    blah
    End if
    %>

    Where blah for example could be a response.redire ct to
    another page displaying the logged off message.

    Note, that you can change the session time out in the IIS
    control panel or using VB script.



    Comment

    • Dominic Marsat

      #3
      Re: Logging in Session Variables Issue

      Or, you could use a form and post the user
      data to each page to avoid using session
      variables

      "Dominic Marsat" <djmarsatAThotm ail.com> wrote in message
      news:u$KbbkpBEH A.3748@TK2MSFTN GP11.phx.gbl...[color=blue][color=green]
      > > 1. Is it a good practice to store the username in a session variable to[/color]
      > keep[color=green]
      > > track of who is logged in?[/color]
      >
      > You don't really have a choice because the HTTP protocol that you
      > use to browse is stateless, therefore, each request for a page is
      > completely independant of earlier requests.
      >
      > Using a session variable is fine. I think it's only really an issue
      > for very busy web servers.
      >
      >[color=green]
      > > 2. Sometimes when a user is logged in for too long without any activity[/color]
      > the[color=green]
      > > session variable clears and when adding or displaying records it gives[/color][/color]
      an[color=blue][color=green]
      > > error. What I would like to do is somehow keep a track and if at all the
      > > session variable expires for it to display a message that "You have been
      > > logged off" please login again but logging in again should take the user
      > > back to the page which logged them out.
      > >[/color]
      >
      > Just check for when the variable contains nothing
      >
      > i.e.
      >
      > <%
      > If Session("user_n ame")="" Then
      > blah
      > End if
      > %>
      >
      > Where blah for example could be a response.redire ct to
      > another page displaying the logged off message.
      >
      > Note, that you can change the session time out in the IIS
      > control panel or using VB script.
      >
      >
      >[/color]


      Comment

      • JP SIngh

        #4
        Re: Logging in Session Variables Issue

        Thanks Dominic

        That was exactly what I was after

        thanks


        "Dominic Marsat" <djmarsatAThotm ail.com> wrote in message
        news:ehN6kupBEH A.3784@TK2MSFTN GP10.phx.gbl...[color=blue]
        > Or, you could use a form and post the user
        > data to each page to avoid using session
        > variables
        >
        > "Dominic Marsat" <djmarsatAThotm ail.com> wrote in message
        > news:u$KbbkpBEH A.3748@TK2MSFTN GP11.phx.gbl...[color=green][color=darkred]
        > > > 1. Is it a good practice to store the username in a session variable[/color][/color][/color]
        to[color=blue][color=green]
        > > keep[color=darkred]
        > > > track of who is logged in?[/color]
        > >
        > > You don't really have a choice because the HTTP protocol that you
        > > use to browse is stateless, therefore, each request for a page is
        > > completely independant of earlier requests.
        > >
        > > Using a session variable is fine. I think it's only really an issue
        > > for very busy web servers.
        > >
        > >[color=darkred]
        > > > 2. Sometimes when a user is logged in for too long without any[/color][/color][/color]
        activity[color=blue][color=green]
        > > the[color=darkred]
        > > > session variable clears and when adding or displaying records it gives[/color][/color]
        > an[color=green][color=darkred]
        > > > error. What I would like to do is somehow keep a track and if at all[/color][/color][/color]
        the[color=blue][color=green][color=darkred]
        > > > session variable expires for it to display a message that "You have[/color][/color][/color]
        been[color=blue][color=green][color=darkred]
        > > > logged off" please login again but logging in again should take the[/color][/color][/color]
        user[color=blue][color=green][color=darkred]
        > > > back to the page which logged them out.
        > > >[/color]
        > >
        > > Just check for when the variable contains nothing
        > >
        > > i.e.
        > >
        > > <%
        > > If Session("user_n ame")="" Then
        > > blah
        > > End if
        > > %>
        > >
        > > Where blah for example could be a response.redire ct to
        > > another page displaying the logged off message.
        > >
        > > Note, that you can change the session time out in the IIS
        > > control panel or using VB script.
        > >
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...