title: Use Signalr to have a facebook like notification system
body: <p>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.</p>
  
  <p>Is signalr suited for such requirement?
  How could i send a notification to a specific user (all opened sessions of this user) using SignalR? </p>
  
  <p>Edit</p>
  
  <p>Ok, Here what i did</p>
  
  <p>In the client side</p>
  
  <pre><code>$(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('&lt;li&gt;' + message + '&lt;/li&gt;');
  };
  // Start the connection
  $.connection.hub.start(function (){
      chat.join(username);
  });
  
  });
  </code></pre>
  
  <p>In the server side</p>
  
  <pre><code>public class Chat : Hub
  {
      public void Join(string username)
      {
          AddToGroup(username);
      }
  }
  </code></pre>
  
  <p>And every time i need to notify a user in the controller i do the following:</p>
  
  <pre><code>IConnectionManager connectionManager = AspNetHost.DependencyResolver.Resolve&lt;IConnectionManager&gt;();
  dynamic clients = connectionManager.GetClients&lt;Chat&gt;();
  clients[username].addMessage("test");
  </code></pre>