show logged in users.

Last post 09-18-2007 1:15 AM by XiaoYong Dai – MSFT. 12 replies.

Sort Posts:

  • show logged in users.

    09-14-2007, 11:31 AM
    • Member
      291 point Member
    • xbhavesh
    • Member since 03-08-2007, 5:15 PM
    • Posts 238

    i have a login screen and when users login i want to show how many users are logged in. can anyone help me out ?

    -------------------------
    Anything is possible.

    If Post.Solved.Problem Then
    " Mark As Answer "
    End If
  • Re: show logged in users.

    09-14-2007, 11:54 AM
    • Contributor
      2,598 point Contributor
    • Sathesh_Pandian
    • Member since 07-23-2007, 3:55 PM
    • Chennai
    • Posts 441

    Add every user in a session transaction.

    public List<Users> ListUsers

    {

    get { return (List<Users>)SesionTransaccion["Users"]; }

    set { SesionTransaccion["Users"] = value; }

    }

     

    after adding them you can get all the users from the collection.

     

    it will work.

    Got what you needed. Please mark as answer.
  • Re: show logged in users.

    09-14-2007, 12:34 PM

    If you are using the default membership provider, you can just use: 

    Membership.GetNumberOfUsersOnline()
     
    When you ask a question, remember to click "mark as answered" when you get a reply which answers your question.


    My latest ASP.NET AJAX blog entries.
  • Re: show logged in users.

    09-14-2007, 1:40 PM
    • Member
      291 point Member
    • xbhavesh
    • Member since 03-08-2007, 5:15 PM
    • Posts 238

    DisturbedBuddha:

    If you are using the default membership provider, you can just use: 

    Membership.GetNumberOfUsersOnline()

     

     

    Not quiet sure about default membership provider ?

    -------------------------
    Anything is possible.

    If Post.Solved.Problem Then
    " Mark As Answer "
    End If
  • Re: show logged in users.

    09-14-2007, 1:43 PM
    • Member
      291 point Member
    • xbhavesh
    • Member since 03-08-2007, 5:15 PM
    • Posts 238

    Sathesh i am using vb code.

    -------------------------
    Anything is possible.

    If Post.Solved.Problem Then
    " Mark As Answer "
    End If
  • Re: show logged in users.

    09-14-2007, 1:48 PM

    I am assuming you are using the the built-in membership features of ASP.NET (using the login controls, etc.).  Otherwise you would have had to write your own code to manage membership (ie, a custom membership provider). 

    Are you using the built-in features?  If so, Membership.GetNumberOfUsersOnline should work.

    When you ask a question, remember to click "mark as answered" when you get a reply which answers your question.


    My latest ASP.NET AJAX blog entries.
  • Re: show logged in users.

    09-14-2007, 1:51 PM
    • Member
      291 point Member
    • xbhavesh
    • Member since 03-08-2007, 5:15 PM
    • Posts 238

    DisturbedBuddha:

    I am assuming you are using the the built-in membership features of ASP.NET (using the login controls, etc.).  Otherwise you would have had to write your own code to manage membership (ie, a custom membership provider). 

    Are you using the built-in features?  If so, Membership.GetNumberOfUsersOnline should work.

     Oh no i am not using the login control.  txtboxes and command button  

    -------------------------
    Anything is possible.

    If Post.Solved.Problem Then
    " Mark As Answer "
    End If
  • Re: show logged in users.

    09-14-2007, 1:59 PM

    Can u post the code that you execute when the user clicks the command button?

    When you ask a question, remember to click "mark as answered" when you get a reply which answers your question.


    My latest ASP.NET AJAX blog entries.
  • Re: show logged in users.

    09-14-2007, 2:04 PM
    • Member
      291 point Member
    • xbhavesh
    • Member since 03-08-2007, 5:15 PM
    • Posts 238
    Sub LoginUser(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Dim aCookie As New System.Web.HttpCookie("forms")

    Dim strUserName As String = Functions.RepairString(usernamebox.Text)Dim strPassword As String = Functions.RepairString(passwordbox.Text)

    strPassword = Functions.Encrypt(strPassword)

    Dim LoginReader As OdbcDataReader = Database.Read("SELECT MEMBER_ID, MEMBER_PASSWORD, MEMBER_LEVEL, MEMBER_VALIDATED, MEMBER_VALIDATION_STRING, MEMBER_DATE_LASTVISIT FROM " & Database.DBPrefix & "_MEMBERS WHERE MEMBER_USERNAME = '" & strUserName & "' and MEMBER_PASSWORD = '" & strPassword & "' and (MEMBER_LEVEL <> 0) and ((MEMBER_LEVEL <> -1 and MEMBER_VALIDATED = 1) or (MEMBER_LEVEL = -1 and MEMBER_VALIDATED = 0))", 1)

    If LoginReader.HasRows Then

    While (LoginReader.Read())

    If (LoginReader("MEMBER_VALIDATED") = 1) Then

    If (rememberbox.Checked()) Then

    aCookie.Values("fighter") = Functions.Encrypt(DateTime.Now())

    aCookie.Values("mukul") = LoginReader("MEMBER_ID").ToString()

    aCookie.Values("dooder") = Functions.Encrypt(DateTime.Now() & "aaa")aCookie.Values("gupta") = LoginReader("MEMBER_PASSWORD").ToString()

    aCookie.Expires = DateTime.Now.AddDays(8)

    Response.Cookies.Add(aCookie)

    End If

    Session("UserName") = strUserName

    Session("UserLogged") = "1"

    Session("UserID") = LoginReader("MEMBER_ID").ToString()

    Session("UserLevel") = LoginReader("MEMBER_LEVEL").ToString()

    If (Session("ActiveLevel") Is Nothing) Or (Session("ActiveLevel") = 3) Then

    Session("ActiveLevel") = 1

    If (Database.DBType = "MySQL") Then

    Session("ActiveTime") = Functions.FormatDate(LoginReader("MEMBER_DATE_LASTVISIT"), 4)

    Else

    Session("ActiveTime") = LoginReader("MEMBER_DATE_LASTVISIT")

    End If

    End If

    DataBase.Write("UPDATE " & Database.DBPrefix & "_MEMBERS SET MEMBER_DATE_LASTVISIT = " & Database.GetTimeStamp() & ", MEMBER_IP_LAST = '" & Request.UserHostAddress() & "' WHERE MEMBER_ID = " & Session("UserID"))

    Response.Redirect(Page.ResolveUrl(Request.Url.ToString()))

    ElseIf ((LoginReader("MEMBER_VALIDATED") = 0) And (Settings.MemberValidation = 2)) Then

    Functions.MessageBox("Incorrect Username/Password")

    aCookie.Values("fighter") = Functions.Encrypt(DateTime.Now())

    aCookie.Values("mukul") = "-3"

    aCookie.Values("dooder") = Functions.Encrypt(DateTime.Now() & "aaa")aCookie.Values("gupta") = Functions.Encrypt(DateTime.Now() & "bbb")

    aCookie.Expires = DateTime.Now.AddDays(-1)

    Response.Cookies.Add(aCookie)

    Session("UserID") = "-1"

    Session("UserName") = ""

    Session("UserLogged") = "0"

    Session("UserLevel") = "0"

    usernamebox.Text = ""

    passwordbox.Text = ""

    Else

    Session("ValidateUserID") = LoginReader("MEMBER_ID").ToString()

    Response.Redirect("validate.aspx")

    End If

    End While

    Else

    Functions.MessageBox("Incorrect Username/Password")

    aCookie.Values("fighter") = Functions.Encrypt(DateTime.Now() & "aaa")

    aCookie.Values("mukul") = "-3"

    aCookie.Values("dooder") = Functions.Encrypt(DateTime.Now() & "bbb")aCookie.Values("gupta") = Functions.Encrypt(DateTime.Now() & "ccc")

    aCookie.Expires = DateTime.Now.AddDays(-1)

    Response.Cookies.Add(aCookie)

    Session("UserID") = "-1"

    Session("UserName") = ""

    Session("UserLogged") = "0"

    Session("UserLevel") = "0"

    usernamebox.Text = ""

    passwordbox.Text = ""

    End If

    LoginReader.Close()

    End Sub

    -------------------------
    Anything is possible.

    If Post.Solved.Problem Then
    " Mark As Answer "
    End If
  • Re: show logged in users.

    09-14-2007, 2:23 PM

    Since you did everything else yourself, I think you are stuck tracking the users yourself.  I suppose you could create an application object (Application("whatever")) and add and subtract one as you authenticate or sign out users, or you could just add another field to your database to indicate if the user is logged in and query the database.  Something like...

    SELECT * FROM whatever WHERE LoggedIn = 1
    RETURN @@ROWCOUNT

    When you ask a question, remember to click "mark as answered" when you get a reply which answers your question.


    My latest ASP.NET AJAX blog entries.
  • Re: show logged in users.

    09-14-2007, 3:36 PM
    • Member
      291 point Member
    • xbhavesh
    • Member since 03-08-2007, 5:15 PM
    • Posts 238

    ok so i created a new page and in its page load i placed

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Response.Write(Session("UserName"))

    End Sub

    which give a user name when a user logs in but it only shows one user. is it possibe to show all users in the session ?

    -------------------------
    Anything is possible.

    If Post.Solved.Problem Then
    " Mark As Answer "
    End If
  • Re: show logged in users.

    09-16-2007, 1:53 PM
    • Member
      291 point Member
    • xbhavesh
    • Member since 03-08-2007, 5:15 PM
    • Posts 238

    ok so i added a field in the table to query this. and when user login i am putting '1' for update and works fine. in my logout button the values updates to '0'. but the thing is when users close the browser without clicking logout it remains '1'

    anything i can do here ?

    -------------------------
    Anything is possible.

    If Post.Solved.Problem Then
    " Mark As Answer "
    End If
  • Re: show logged in users.

    09-18-2007, 1:15 AM
    Answer

     

    xbhavesh:

    ok so i added a field in the table to query this. and when user login i am putting '1' for update and works fine. in my logout button the values updates to '0'. but the thing is when users close the browser without clicking logout it remains '1'

    Hi

    Cannot detect the browser close but you can update the state in Session_End event,

    http://forums.asp.net/p/1049599/1479987.aspx#1479987

    Best Regards
    XiaoYong Dai
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Page 1 of 1 (13 items)