Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I list members online (for a chatroom)

Posted on 2013-11-05
4
Medium Priority
?
192 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 1200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Screencast - Getting to Know the Pipeline

916 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