ASP.NET C # - метод уведомлений в реальном времени - PullRequest
0 голосов
/ 14 ноября 2011

Как вы думаете, это плохой способ получения уведомлений?Этот WebMethod будет вызываться каждые 10 секунд с помощью JavaScript.Есть ли лучший способ сделать это?Если так, пожалуйста, уточните.Спасибо.

[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;
}

1 Ответ

6 голосов
/ 14 ноября 2011

Проверьте библиотеку асинхронной сигнализации SignalR для ASP.NET.

...