简体   繁体   English

ASP.NET C#-实时通知方法

[英]ASP.NET C# - A Real-Time Notifications Method

Do you think this is a bad way to retrieve notifications? 您是否认为这是检索通知的不好方法? This WebMethod will be called each 10 seconds by JavaScript. JavaScript将每10秒调用一次此WebMethod。 Is there any better way of doing this? 有什么更好的方法吗? If so please elaborate. 如果是这样,请详细说明。 Thank you. 谢谢。

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

检出ASP.NET的SignalR异步信令库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM