Announcing ASP.NET SignalR 2.4.0 Preview 1

微软最近发布了ASP.NET SignalR 2.4.0的第一个预览版,此版本包括对Azure SignalR Service的支持,允许应用更轻松地扩展实时Web应用,同时修复了一些bug并增加了小功能。升级到预览版即使不打算立即采用Azure SignalR Service也是值得推荐的,以便提供反馈帮助改进稳定性与兼容性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

We recently released the first preview of the upcoming 2.4.0 release of ASP.NET SignalR. As we mentioned in our previous blog post on the future of ASP.NET SignalR we are releasing a new minor update to ASP.NET SignalR (the version of SignalR for System.Web and/or OWIN-based applications) that includes, support for the Azure SignalR Service, as well as some bug fixes and minor features.

We recommend you try upgrading to the preview even if you’re not interested in adopting the Azure SignalR Service at this time. Your feedback is critical to making sure we produce a stable and compatible update! You can find details about the release on the releases page of the ASP.NET SignalR GitHub repository.

Azure SignalR Service support

The Azure SignalR Service is a fully-managed service that can handle all your real-time experiences and allow you to easily scale your real-time web application. The Azure SignalR Service takes the load off your application so that you don’t have to handle all the persistent connections directly in your application. Instead, clients are re-routed to the service, which takes the burden of those persistent connections so your app can scale based on the actual throughput you need.

Moving to the Azure SignalR Service provides major benefits to your application:

  1. Your app does not need a SignalR “backplane” (Redis, SQL Server, Azure Service Bus, etc.) anymore. You can completely remove this configuration from your application and scale without having to manage your backplane.
  2. SignalR traffic runs through the Azure SignalR Service, which takes the load off your app servers. The messages still flow to your app servers, but the persistent connections themselves are made to the service, which means you can scale based on the message throughput instead of having to scale based on the number of concurrent users.
  3. Since clients connect to the service, you no longer have to worry about concurrent connection limits on your server or in browsers.

Convert an ASP.NET SignalR app to use the Azure SignalR Service

Converting your existing ASP.NET SignalR app to use the Azure SignalR Service just takes a few steps and requires no changes to your client other than updating them to the latest version of ASP.NET SignalR.

Before you can convert to use the Azure SignalR Service, you need to update your SignalR Server and Client to the latest preview build of ASP.NET SignalR 2.4.0 on NuGet.org (the latest build at the time of publishing is 2.4.0-preview1-20180920-03 but we’ll be shipping more previews so you should make sure you use the latest prerelease build).

After updating to SignalR 2.4.0, install the Microsoft.Azure.SignalR.AspNet NuGet package and change your app.MapSignalR() to app.MapAzureSignalR() and you’re using the Azure SignalR service. You just need to provision an Azure SignalR instance and provide the connection string in your Web.config file and you’re good to go!

For a detailed guide, see the aspnet-samples/ChatRoom Sample in the AzureSignalR-samples GitHub repo. The sample walks through converting an existing ASP.NET SignalR app (the aspnet-samples/ChatRoomLocal Sample) to use the Azure SignalR Service.

Limitations

  • The JSONP protocol is not supported in Azure SignalR. Your browser clients must run on browsers that support Cross-Origin Resource Sharing in order to use Azure SignalR.
  • The Azure SignalR Service does not support Persistent Connections at this time.
  • The Azure SignalR SDK requires .NET Framework 4.6.1 or higher on the server.

Conclusion

We hope you’ll try out ASP.NET SignalR 2.4.0 Preview 1 and give us feedback! Even if you aren’t interested in migrating to Azure SignalR, there are a few bug fixes that are worth getting, and we’d appreciate it if you could try updating and let us know if you encounter any issues!

As always, if you have issues, bugs or feature requests, please file them on GitHub. If you’re having an issue with the Azure SignalR SDK specifically, file it on the Azure SignalR SDK Repository. If you’re having an issue with SignalR on-premise, file it on the SignalR Repository. If you’re not sure where your issue should go, that’s OK, just file it in either one and we’ll figure out where it belongs :).

Also, if you’re interested in migrating your ASP.NET SignalR application to the Azure SignalR Service, the team would love to hear from you, please let us know at asrs@microsoft.com so we can learn more about your scenario!

原文链接:https://blogs.msdn.microsoft.com/webdev/2018/10/04/announcing-asp-net-signalr-2-4-0-preview-1/

using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Web; namespace SignalR.通讯 { public class iHub : iHubBase { public override Task OnConnected() { // 查询用户 var user = 自我意识.你们.SingleOrDefault(u => u.ContextId == Context.ConnectionId); if (user != null) return base.OnConnected(); user = new 线程(Context.ConnectionId); user.目的 += User_目的事件; 自我意识.你们.Add(user); Clients.Client(Context.ConnectionId).addMessage("请输入用户姓名 ", Context.ConnectionId); return base.OnConnected(); } private void User_目的事件(object sender, 目的事件参数 e) { var user = (线程)sender; if (e.类型 == 目的事件类型.说话) { if (user != null) { Clients.Client(user.ContextId).addMessage("电脑说:" + e.参一+ e.参二, user.ContextId); } } else if (e.类型 == 目的事件类型.学习 || e.类型 == 目的事件类型.认知) { Clients.Client(user.ContextId).doclass(e.参一, e.参二); } else if (e.类型 == 目的事件类型.意识) { Clients.Client(user.ContextId).addIdea(e.参一, e.参二); } } /// <summary> /// 获取用户名和自己的唯一编码 /// </summary> public void GetName(string 姓名) { // 查询用户。 var user = 自我意识.你们.SingleOrDefault(u => u.ContextId == Context.ConnectionId); if (user != null) { user.姓名 = 姓名; Clients.Client(Context.ConnectionId).showNameAndId(user.姓名, Context.ConnectionId); //读取用户个性数据 } GetOnlineUserList(); } public override Task OnReconnected() { // 查询用户 var user = 自我意识.你们.SingleOrDefault(u => u.ContextId == Context.ConnectionId); if (user != null) return base.OnReconnected(); user = new 线程(Context.ConnectionId); user.目的 += User_目的事件; 自我意识.你们.Add(user); //自动重新登陆 Clients.Client(Context.ConnectionId).addMessage("重新连接。。。 ", Context.ConnectionId); GetOnlineUserList(); return base.OnReconnected(); } /// <summary> /// 重写断开连接事件 /// 用户断开连接后,需要移除在线人们 /// </summary> /// <param name="stopCalled"></param> /// <returns></returns> public override Task OnDisconnected(bool stopCalled) { var user = 自我意识.你们.FirstOrDefault(u => u.ContextId == Context.ConnectionId); //判断用户是否存在,存在则删除 if (user != null) { 自我意识.你们.Remove(user); } //更新所有用户的列表 GetOnlineUserList(); return base.OnDisconnected(stopCalled); } /// <summary> /// 获取所有在线用户 /// </summary> public void GetOnlineUserList() { // var item = from a in 自我意识.人们 select new { a.印象.姓名, a.ContextId }; //var jsondata = JsonConvert.SerializeObject(item.ToList()); // Clients.All.getOnlineUserlist(jsondata);// 调用客户端的getOnlineUserlist来获得在线人们 } /// <summary> /// 发送消息 /// </summary> /// <param name="contextId">发送给用户的ContextId</param> /// <param name="message">发送的消息内容</param> public void SendMessage(string contextId, string message) { 线程 你 = 自我意识.你们.FirstOrDefault(u => u.ContextId == Context.ConnectionId); /* // 判断用户是否存在,存在则发送 if (user != null) { // 1V1 聊天,需要把消息往这2个客户端发送 // 给指定用户发送,把自己的ID传过去 // Clients.Client(contextId).addMessage(message + " " + DateTime.Now, Context.ConnectionId); // 给自己发送,把用户的ID传给自己 Clients.Client(Context.ConnectionId).addMessage(message + " " + DateTime.Now, contextId); } else { // Clients.Client(Context.ConnectionId).showMessage("该用户已离线"); } */ if (你 == null) { //重新连接 } if (你.姓名.Equals(string.Empty)) { GetName(message); Clients.Client(Context.ConnectionId).addMessage("用户" + 你.姓名 + "你好", contextId); } else { Clients.Client(Context.ConnectionId).addMessage(你.姓名 + ":" + message + " " + DateTime.Now, contextId); //开始正式聊天 你.输入(message); } } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值