本文共 1266 字,大约阅读时间需要 4 分钟。
html代码:
hub代码:
[HubName("payHub"), Authorize] public class payHub : Hub { public static DictionaryuserPayHub = new Dictionary (); public static void Notify(Guid userId, string redirectUrl) { if (userPayHub.ContainsKey(userId)) { Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext () .Clients.Client(Hubs.payHub.userPayHub[userId]) .waitNotify(true, redirectUrl); } } public override Task OnConnected() { var uid = this.Context.User.Identity.GetUserId(); userPayHub[uid] = this.Context.ConnectionId; return base.OnConnected(); } public override Task OnDisconnected(bool stopCalled) { var uid = this.Context.User.Identity.GetUserId(); userPayHub.Remove(uid); return base.OnDisconnected(stopCalled); } public override Task OnReconnected() { var uid = this.Context.User.Identity.GetUserId(); userPayHub.Remove(uid); return base.OnReconnected(); } }
通知调用Notify方法即可。
关键点:GlobalHost.ConnectionManager.GetHubContext
转载地址:http://omnna.baihongyu.com/