【问题标题】:ASP.NET C# - A Real-Time Notifications MethodASP.NET C# - 一种实时通知方法
【发布时间】:2011-11-14 03:37:38
【问题描述】:

您认为这是检索通知的坏方法吗? 此 WebMethod 将由 JavaScript 每 10 秒调用一次。有没有更好的方法来做到这一点?如果是,请详细说明。谢谢。

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public int[] GetNotifications()
{
    int[] Notifications = new int[3]{0, 0, 0};
    if (HttpContext.Current.User.Identity.IsAuthenticated) {
        string UserName = HttpContext.Current.User.Identity.Name;
        Notifications[0] = Notification.GetAll(UserName, false).Count;
        Notifications[1] = Message.GetAll(UserName, false).Count;
        Notifications[2] = Friendship.GetFriends(UserName, true).Count;
    }
    return Notifications;
}

【问题讨论】:

  • 查看 Comet 或反向 AJAX。

标签: c# javascript asp.net asmx webmethod


【解决方案1】:

查看用于 ASP.NET 的 SignalR 异步信号库。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-20
  • 2020-10-18
  • 1970-01-01
  • 1970-01-01
  • 2021-06-05
  • 2013-03-09
相关资源
最近更新 更多