【发布时间】: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