问题描述
我要实现像ASP.NET MVC 3通报制度Facebook的:通知发送给特定的用户,通知他在他的项目中的一个动作
。时signalr适合这样的要求?
我怎么能一个通知发送到使用SignalR特定用户(该用户的所有会议开幕)?
修改
好吧,这里我做了什么
在客户端
$(函数(){
//代理动态创建
VAR聊天= $ .connection.chat;
VAR用户名='@ Html.ViewContext.HttpContext.User.Identity.Name';
//声明聊天枢纽功能使服务器可以调用它
chat.addMessage =功能(消息){
$('#消息)追加('<立GT;'+信息+'< /李>');
};
//开始连接
$ .connection.hub.start(函数(){
chat.join(用户名);
});});
在服务器侧
公共类聊天:集线器
{
公共无效注册(用户名字符串)
{
AddToGroup(用户名);
}
}
我每次需要在控制器I执行以下操作来通知用户:
IConnectionManager的ConnectionManager = AspNetHost.DependencyResolver.Resolve< IConnectionManager>();
动态的客户端= connectionManager.GetClients<聊天和GT;();
客户端[用户名] .addMessage(测试);
这是适当的,或者你使用轮询,这些都是两个选择。
继承人从今天起一个全新的视频这样的:
<一个href=\"http://channel9.msdn.com/Shows/Web+Camps+TV/Damian-Edwards-and-David-Fowler-Demonstrate-SignalR?utm_source=dlvr.it&utm_medium=twitter\" rel=\"nofollow\">http://channel9.msdn.com/Shows/Web+Camps+TV/Damian-Edwards-and-David-Fowler-Demonstrate-SignalR?utm_source=dlvr.it&utm_medium=twitter
I want to implement a facebook like notification system in ASP.NET MVC 3 : notifications are sent to a specific user to notify him for an action on one of his items.
Is signalr suited for such requirement?How could i send a notification to a specific user (all opened sessions of this user) using SignalR?
Edit
Ok, Here what i did
In the client side
$(function () {
// Proxy created on the fly
var chat = $.connection.chat;
var username = '@Html.ViewContext.HttpContext.User.Identity.Name';
// Declare a function on the chat hub so the server can invoke it
chat.addMessage = function (message) {
$('#messages').append('<li>' + message + '</li>');
};
// Start the connection
$.connection.hub.start(function (){
chat.join(username);
});
});
In the server side
public class Chat : Hub
{
public void Join(string username)
{
AddToGroup(username);
}
}
And every time i need to notify a user in the controller i do the following:
IConnectionManager connectionManager = AspNetHost.DependencyResolver.Resolve<IConnectionManager>();
dynamic clients = connectionManager.GetClients<Chat>();
clients[username].addMessage("test");
It is appropriate for this or you use polling, those are the two choices.
Heres a brand new video from today on this:
这篇关于使用Signalr有这样的通知系统的Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!