Solved

How can I list members online (for a chatroom)

Posted on 2013-11-05
4
187 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Initial get page response times and IIS8 15 55
ASP.net File format issue in producing Excel file 3 49
Finding the IIS version 5 22
reading excel file in .net 2 18
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 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