KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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");
Tags (comma-separated)
Save Edits
Cancel