Solved

How can I list members online (for a chatroom)

Posted on 2013-11-05
4
190 Views
Last Modified: 2013-11-17
Hi I don't use .Net Membership, I just store the username and password in the database and work with Sessions, storing the UserId in a Session var when he/she is logged on.  I'm not really sure where to start on this so any pointers would be good :-)
0
Comment
Question by:Lorna70
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Expert Comment

by:johny_bravo1
ID: 39628073
Not sure what exactly you need.
Validate your user against database and if the login is valid, assign a Session to the user.

 SqlCommand cmd = new SqlCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            DataTable dt = new DataTable();
            try
            {
                cmd = new SqlCommand("Select * from User where UserName = '"+txtUserName.Text+"' And Pass = '"+txtPass.Text+"'", yourConnection);
                da.SelectCommand = cmd;
                da.Fill(dt);
if(dt.Rows.Count > 0)
{
Session["UserName"] = txtUserName.Text;
}

            }

Then on logout you can clear this session.
0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 39632097
does the number need to be dynamic e.g. user doesn't have to refresh the browser, think of facebooks right hand ticker, how many users are we talking now, next year?

simple way ajax polling hitting the db/app cache for a count
better way ajax and cache invalidation with a cache store
better better way hub with push

you can also be funky and give them estimated numbers google'ish style...
0
 

Author Comment

by:Lorna70
ID: 39632776
Thanks guys but I don't think you read the subject of my post - it's the actual user names of those logged on that I need, so anyone who wants to chat can select someone to chat to from the list - just like on facebook.  My problem is that my hosting company doesn't have the minimum requirements for SignalR.  I know I can store the names of those logged on but what happens when they close their browsers or log out - I need to be able ot remove them from the list (or store in the db that they have logged out.
0
 
LVL 12

Accepted Solution

by:
deanvanrooyen earned 300 total points
ID: 39634853
you will have the messages posted in some of database? use some sort of sliding expiration on the last comment posted or invalidate on explicit logout? @TheLearnedOne posted in a recent thread about asp.net and creating your own background worker thread, that might be an option if you are on an isp. I would shy away from this solution though because any sort of thread management outside of the worker processes could be leading you down a pathway of pain if your not up for the challenge...

 e.g. the thread could kick off and poll every xx seconds for active users, then invalidate them after say 20 minutes of inactivity. Explicit logout removes username etc.

you could use some js methods to detect browser closing and fire of an sync call again to remove user name.

<links removed - GaryC123>

I would store username in a cache layer - if you cannot then use ioc, with a repository that just holds a list of names , make the repo singleton scope. When the user logs in get the list, add the user to the list, use the browser detection to remove a user, explicit logout then remove the user.  Then if you want to get fancy separate thread that invalidates users in the list based on what ever business rules you want... and because you cannot push updates to each client you will have to poll to keep the list fresh locally.

ps this is sort of a poc thought process, and would likely not be the end solution. The other thing is there is probably already pre built asp.net apps like this  - just checkout git hub or the like...
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question