알림을 검색하는 것이 좋지 않다고 생각하십니까? 이 WebMethod는 JavaScript로 10 초마다 호출됩니다. 이 작업을 수행하는 더 좋은 방법이 있습니까? 그렇다면 정교하게하십시오. 고맙습니다.ASP.NET C# - 실시간 알림 방법
[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;
}
혜성을 들여다 보거나 AJAX를 뒤집습니다. – SLaks