Solved

How can I list members online (for a chatroom)

Posted on 2013-11-05
4
181 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now