博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SignalR主动通知订阅者示例
阅读量:4451 次
发布时间:2019-06-07

本文共 1317 字,大约阅读时间需要 4 分钟。

html代码:

hub代码:

[HubName("payHub"), Authorize]    public class payHub : Hub    {        public static Dictionary
userPayHub = 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

转载于:https://www.cnblogs.com/calvinK/p/5345511.html

你可能感兴趣的文章
LeetCode--018--四数之和(java)
查看>>
Redis消息队列
查看>>
电商网站架构设计
查看>>
http://jingyan.baidu.com/article/4dc40848e7b69bc8d946f127.html
查看>>
WCF netTcp配置
查看>>
数据类型转换
查看>>
Nodejs学习笔记(2) 阻塞/非阻塞实例 与 Nodejs事件
查看>>
什么是FreeMaker
查看>>
设计模式学习笔记(总结篇:模式分类)
查看>>
TCP的三次握手/建立连接
查看>>
Python 教程阅读笔记(一):使用解释器
查看>>
运算符重载
查看>>
SDWebImage 新版接口使用方法
查看>>
DataTable导出为word,excel,html,csv,pdf,.txt
查看>>
android ListView详解
查看>>
软件工程 第一次作业
查看>>
Content Server HA搭建
查看>>
vue-textarea 自适应高度
查看>>
(2)数据结构——线性表(链表)实现
查看>>
[leetCode]Linked List Cycle I+II
查看>>