ASP.NET MVC Update views for specific user after change in database

I'am creating an appliaction in ASP.NET MVC 5 with SQL Server where one of the module is a News. News can be added by Administrator to main page. Users can comment the news. I would like to know how to implement real-time adding comments to news, which means that when user is reading for example news with ID=5 and somebody post a comment in this news i would like to get this comment without refreshing the page. I heard about SignalR ,but i don't know how to call update ONLY FOR USERS who are reading a specific news with for example ID=5.How to send update only for this users? Not for all logged in users, but only for a specific users which are currently on the specific news?

Answers 1

  • If you decide to use SignalR for your implementation you may read about Groups:

    Groups in SignalR provide a method for broadcasting messages to specified subsets of connected clients. A group can have any number of clients, and a client can be a member of any number of groups. You don't have to explicitly create groups. In effect, a group is automatically created the first time you specify its name in a call to Groups.Add, and it is deleted when you remove the last connection from membership in it.

    So in your case when a user opens a news you can add it to a server group with the specified news id. And when a user comments on some news, you could broadcast to all clients connected to the specified group.

Related Articles