Solved

How can I list members online (for a chatroom)

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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.…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 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