试图避免服务器上的流量

Trying to avoid Traffic on Server

我正在使用 C# ASP.NET MVC 4 Razor

我在 ASP.NET MVC Razor 视图中有一个显示用户记录的网格。有什么方法可以在不每 1 分钟后向服务器发送异步请求的情况下在 Grid 中显示新用户?

我在 Google 上搜索了很多。现在,最后我在这里发布查询以获得此解决方案的任何线索,以避免服务器上的流量。由于此页面将对至少 20,000 名用户可见

您可以使用 publish/subscriber 模式。这可以使用例如 redis 服务器来完成。

In software architecture, publish–subscribe is a messaging pattern where senders of messages, called publishers, do not program the messages to be sent directly to specific receivers, called subscribers. Instead, published messages are characterized into classes, without knowledge of what, if any, subscribers there may be. Similarly, subscribers express interest in one or more classes, and only receive messages that are of interest, without knowledge of what, if any, publishers there are.

请看here.

这样做,客户端第一次从服务器请求数据时将订阅服务器以获取任何更新。一旦任何更新到达,服务器会将更新推送到已订阅的客户端,而不需要客户端向服务器发出任何其他请求。

具体实现请看here

@Christos 方法是正确的方法!,只是为 ASP.NET 解决方案添加更多信息,我会使用 SignalR,它可以让你实现一个简单的 server/client 通信并且它是交叉的浏览器(它有几个 polyfill,如果它不能使用 web 套接字,它将使用服务器发送的事件,等等),最好的部分是你不需要担心那个实现。

一旦您的客户端连接到 signalR 服务器,您就可以在每次需要向网格中添加新项目时通知他们。

http://www.asp.net/signalr/overview/getting-started/tutorial-server-broadcast-with-signalr

希望对您有所帮助!