我使用asp.net mvc开发聊天应用程序 [英] iam developing a chat application using asp.net mvc

查看:171
本文介绍了我使用asp.net mvc开发聊天应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai,

我正在使用asp.net mvc开发一个聊天应用程序。对于这个iam使用signalr.But我没有得到的是每当用户登录时我必须将特定用户状态设置为在线(如显示绿色),如果用户离线,我必须更改状态(红色)。请帮我这样做....

这里是我的jquery代码,其中iam绑定用户(从db获取)

Hai,
Iam developing a chat application using asp.net mvc.For this iam using signalr.But what iam not getting is whenever the user login i have to make the particular user status as online(like showing green),and if the user goes offline i have to change status(as red).Please help me in doing this....
here is my jquery code where iam binding the users(fetching from db)

chat.server.getConnectedUsers().done(function (class1) {

            usernameList.empty();
            for (var i = 0; i < class1.length; ++i) {
                if (class1[i].username != _chatUsername) {
                    usernameList.append(class1[i].username);
                    

                }
            }

        });



添加了代码块格式[/ Edit]


Code block formatting added[/Edit]

推荐答案

有一个名为OnDisconnect方法的重写方法。在这个方法中,取下断开连接的conectionId。从上下文中你可以获得断开连接的用户connectionId Context.ConnectionId 并使用户离线。

There is a overriding method called OnDisconnect method. In this method take the conectionId who disconnect .from the Context you can get the disconnected user connectionId Context.ConnectionId and make the user as offline.
public override Task OnDisconnected()
{
}





希望这有帮助



Hope this helps


这篇关于我使用asp.net mvc开发聊天应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆