当前位置: 首页 > news >正文

做ic哪些网站好做山西 网站建设

做ic哪些网站好做,山西 网站建设,盾思途旅游网站建设,wordpress和django假设需要通过SignalR发送消息通知#xff0c;并在前端接收消息通知的功能 创建SignalR服务 在项目中引用 abp add-package Volo.Abp.AspNetCore.SignalR在Module文件中添加对模块依赖 [DependsOn(...typeof(AbpAspNetCoreSignalRModule))] public class IdentityApplicati…假设需要通过SignalR发送消息通知并在前端接收消息通知的功能 创建SignalR服务 在项目中引用 abp add-package Volo.Abp.AspNetCore.SignalR在Module文件中添加对模块依赖 [DependsOn(...typeof(AbpAspNetCoreSignalRModule))] public class IdentityApplicationModule : AbpModule创建接口INotificationHub public interface INotificationHub {// 发送消息Task ReceiveTextMessageAsync(SendNotificationDto input); } 也可以不创建接口AbpHub类定义了泛型和非泛型的类型。 创建NotificationHub类继承AbpHub。 可以直接继承Microsoft.AspNetCore.SignalR.Hub但是这样就不能使用已注入的属性如 CurrentUser /// summary /// SignalR消息Hub /// /summary [HubRoute(signalr/Identity/notification)] [Authorize] [DisableAuditing] public class NotificationHub : AbpHubINotificationHub {}发送SignalR消息 在需要调用的地方注入IHubContext并初始化 private readonly IHubContextNotificationHub, INotificationHub _hubContext; public NotificationAppService(IHubContextNotificationHub, INotificationHub hubContext) {_hubContext hubContext; }使用下面的方式发送给指定用户或者所有用户 public async Task SendMessageToUsersAsync(Liststring userIds, SendNotificationDto sendNotificationDto) {await _hubContext.Clients.Users(userIds.AsReadOnly().ToList()).ReceiveTextMessageAsync(sendNotificationDto); }public async Task SendMessageToAllAsync(SendNotificationDto sendNotificationDto) {await _hubContext.Clients.All.ReceiveBroadCastMessageAsync(sendNotificationDto); }配置Ocelet网关 为/signalr/identity/路由创建转发规则 当SignalR开始连接时首先发送协商协议请求协商协议返回availableTransports告诉客户端支持哪些协议以及connetcionId和connectionToken这两个值会在后续的连接中使用。 在当前路由配置下请求地址是/signalr/identity/negotiate此http请求会通过网关转发到IdentityServer。 在Gateway项目的appsettings.json中配置网关转发规则如下 Routes: [{DownstreamPathTemplate: /signalr/identity/{everything},DownstreamScheme: http,DownstreamHostAndPorts: [{Host: localhost,Port: 44368}],UpstreamPathTemplate: /signalr/identity/{everything},UpstreamHttpMethod: [ Put, Delete, Get, Post ]},...除此之外还要配置ws协议的转发规则SignalR首先尝试建立WebSocket连接WebSocket是 SignalR的最佳传输方式配置如下 {DownstreamPathTemplate: /signalr/identity/{everything},DownstreamScheme: ws,Priority: 1,DownstreamHostAndPorts: [{Host: localhost,Port: 44368}],UpstreamPathTemplate: /signalr/identity/{everything},UpstreamHttpMethod: [ Put, Delete, Get, Post ]},尽量使用kestrel运行网关程序IIS7.0之前不支持websocket若使用IIS请确保Websocket功能已经打开。 在UseOcelot()之前添加UseWebSockets()以便网关能接收ws或wss协议的请求。若不加这个网关会在转发时返回499错误码。 app.UseWebSockets(); app.UseOcelot().Wait();创建SignalR客户端 客户端安装取决于你的UI框架/客户端类型。若使用Asp.NetCore MVC或Razor请参考abp官方文档 这里补充其他UI框架的使用方法。在webpackage项目中添加对SignalR的依赖 yarn add microsoft/signalr创建一个hubConnection 在main.js中添加如下代码 const hubConnection: signalR.HubConnection new signalR.HubConnectionBuilder().withUrl(baseURL requestUrl, {headers: header,accessTokenFactory: () getAccessToken(),transport: signalR.HttpTransportType.WebSockets,logMessageContent: true,logger: signalR.LogLevel.Information,}).withAutomaticReconnect().withHubProtocol(new signalR.JsonHubProtocol()).build();accessTokenFactory回调用于获取access_token的会在每次请求时调用以保证获取最新的access_token。 连接服务 在需要使用的地方调用hubConnection方法 hubConnection.start() //开始连接 hubConnection.stop() //停止连接订阅消息 hubConnection.on(ReceiveTextMessage, (newMsg) {console.info(new msg recived!, newMsg) });身份验证 WebSockets不支持自定义Header所以不能使用Authorization需要使用access_token参数传递令牌 客户端 在客户端中配置getAccessToken如下 const getAccessToken: Function (): string {var token UserModule.token ! undefined ? UserModule.token : ; return token; }UserModule.token是当前登录用户的token需要在登录成功后保存到UserModule中。 服务端 在服务端中若已经使用了IdentityServer则需要在Startup中配置IdentityServerAuthentication配置如下 context.Services.AddAuthentication(Bearer).AddIdentityServerAuthentication(options {options.Authority configuration[AuthServer:Authority];options.ApiName configuration[AuthServer:ApiName];options.RequireHttpsMetadata Convert.ToBoolean(configuration[AuthServer:RequireHttpsMetadata]);options.TokenRetriever (request) {var path request.Path;if (path.StartsWithSegments(/signalr)){var accessToken request.Query[access_token].FirstOrDefault();if (!accessToken.IsNullOrWhiteSpace()){return accessToken;}}return TokenRetrieval.FromAuthorizationHeader().Invoke(request);}; }); 如果你适用IISExpress运行项目注意此时SignalR的url参数可能过长而报告404.15 - Query String Too LongIIS默认限制是2048需要在C:\Windows\System32\inetsrv\config\applicationHost.config中配置maxQueryString规则如下 configurationsystem.webServersecurityrequestFilteringrequestLimits maxQueryString4096 //requestFiltering/security/system.webServer /configuration
http://www.hkea.cn/news/14537101/

相关文章:

  • html做的网页怎么变成网站学网站设计培训电话
  • 佛山网站建设公司怎么选长沙装修网站排名
  • 池州网站制作大连做网站谁家好
  • 网站美化教程下载wordpress自定义字段类型
  • 网络公司网站设计多少钱青海wap网站建设公司
  • 上海外贸soho网站建设网站开发工作量
  • 湖北平台网站建设制作网站制作需要网站制作
  • 深圳企业社保网站官网贵州省中海工程建设有限公司网站
  • 外销网站建设国内最新消息
  • 腾讯云做网站步骤网站建设有利于
  • 网站申请备案成功后怎么建设电子商务网站建设市场分析
  • 公司备案网站名称重写Wordpress的js
  • 网站微信建设运维经验pos机做网站推广
  • 山东卓创 网站建设东莞网站建设包装制品
  • 建设银行官网首页 网站一级网站和二级网站的区别
  • 网站如何做引流做网站具体流程
  • 免费个人微网站模板柳州免费做网站的公司
  • 惠州建设银行行号查询网站乐陵网站建设
  • 网站建设 天津世界顶尖名表瑞士网站不要中国手表网站
  • 潍坊网站优化公司廊坊首页霸屏排名优化
  • 网站默认后台登陆升级网站
  • 网页设计网站多少钱网站需要维护
  • 网站开发业务流程网站封面怎么做
  • 大连城乡建设网站网站建设项目需求书
  • 网站运营与管理试卷最佳商城ui网站设计
  • 做网站还得备案白石桥做网站公司
  • 做app的网站有哪些功能吗o2o模式是什么意思通俗讲
  • 免费数据分析网站在线看mv视频网站入口软件下载
  • 贵州企业网站建设公司徐州网站定制
  • 网站开发专业都有哪些课程wordpress 网校插件