Догађаји
Поwер БИ ДатаВиз Светско првенство
14. феб 16 - 31. мар 16
Са 4 шансе за улазак, можете освојити конференцијски пакет и стићи до ЛИВЕ Гранд Финале у Лас Вегасу
Сазнајте вишеОвај прегледач више није подржан.
Надоградите на Microsoft Edge бисте искористили најновије функције, безбедносне исправке и техничку подршку.
ASP.NET Core SignalR isn't compatible with clients or servers for ASP.NET SignalR. This article details features which have been removed or changed in ASP.NET Core SignalR.
ASP.NET SignalR | ASP.NET Core SignalR | |
---|---|---|
Server NuGet package | Microsoft.AspNet.SignalR | None. Included in the Microsoft.AspNetCore.App shared framework. |
Client NuGet packages | Microsoft.AspNet.SignalR.Client Microsoft.AspNet.SignalR.JS |
Microsoft.AspNetCore.SignalR.Client |
JavaScript client npm package | signalr | @microsoft/signalr |
Java client | GitHub Repository (deprecated) | Maven package com.microsoft.signalr |
Server app type | ASP.NET (System.Web) or OWIN Self-Host | ASP.NET Core |
Supported server platforms | .NET Framework 4.5 or later | .NET Core 3.0 or later |
ASP.NET SignalR | ASP.NET Core SignalR | |
---|---|---|
Server NuGet package | Microsoft.AspNet.SignalR | Microsoft.AspNetCore.App (.NET Core) Microsoft.AspNetCore.SignalR (.NET Framework) |
Client NuGet packages | Microsoft.AspNet.SignalR.Client Microsoft.AspNet.SignalR.JS |
Microsoft.AspNetCore.SignalR.Client |
JavaScript client npm package | signalr | @aspnet/signalr |
Java client | GitHub Repository (deprecated) | Maven package com.microsoft.signalr |
Server app type | ASP.NET (System.Web) or OWIN Self-Host | ASP.NET Core |
Supported server platforms | .NET Framework 4.5 or later | .NET Framework 4.6.1 or later .NET Core 2.1 or later |
In ASP.NET SignalR:
In ASP.NET Core SignalR:
HubConnection connection = new HubConnectionBuilder()
.WithUrl(new Uri("http://127.0.0.1:5000/chathub"))
.WithAutomaticReconnect()
.Build();
const connection = new signalR.HubConnectionBuilder()
.withUrl("/chathub")
.withAutomaticReconnect()
.build();
Prior to ASP.NET Core 3.0, SignalR doesn't support automatic reconnects. If the client is disconnected, the user must explicitly start a new connection to reconnect. In ASP.NET SignalR, SignalR attempts to reconnect to the server if the connection is dropped.
ASP.NET Core SignalR supports JSON, as well as a new binary protocol based on MessagePack. Additionally, custom protocols can be created.
The Forever Frame transport isn't supported in ASP.NET Core SignalR.
The ASP.NET Core SignalR server-side libraries are included in Microsoft.AspNetCore.App, which is used in the ASP.NET Core Web Application template for both Razor and MVC projects.
ASP.NET Core SignalR is an ASP.NET Core middleware. It must be configured by calling AddSignalR in Startup.ConfigureServices
.
services.AddSignalR()
To configure routing, map routes to hubs inside the UseEndpoints method call in the Startup.Configure
method.
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<ChatHub>("/hub");
});
To configure routing, map routes to hubs inside the UseSignalR method call in the Startup.Configure
method.
app.UseSignalR(routes =>
{
routes.MapHub<ChatHub>("/hub");
});
The scaleout model for ASP.NET SignalR allows clients to reconnect and send messages to any server in the farm. In ASP.NET Core SignalR, the client must interact with the same server for the duration of the connection. For scaleout using Redis, that means sticky sessions are required. For scaleout using Azure SignalR Service, sticky sessions aren't required because the service handles connections to clients.
In ASP.NET Core SignalR, the connection model has been simplified. Connections are made directly to a single hub, rather than a single connection being used to share access to multiple hubs.
ASP.NET Core SignalR now supports streaming data from the hub to the client.
The ability to pass arbitrary state between clients and the hub (often called HubState
) has been removed, as well as support for progress messages. There is no counterpart of hub proxies at the moment.
In ASP.NET Core SignalR, the PersistentConnection class has been removed.
ASP.NET Core has dependency injection (DI) built into the framework. Services can use DI to access the HubContext. The GlobalHost
object that is used in ASP.NET SignalR to get a HubContext
doesn't exist in ASP.NET Core SignalR.
ASP.NET Core SignalR doesn't have support for HubPipeline
modules.
The ASP.NET Core SignalR client is written in TypeScript. You can write in JavaScript or TypeScript when using the JavaScript client.
In ASP.NET versions, the JavaScript client was obtained through a NuGet package in Visual Studio. In the ASP.NET Core versions, the @microsoft/signalr
npm package contains the JavaScript libraries. This package isn't included in the ASP.NET Core Web Application template. Use npm to obtain and install the @microsoft/signalr
npm package.
npm init -y
npm install @microsoft/signalr
In ASP.NET versions, the JavaScript client was obtained through a NuGet package in Visual Studio. In the ASP.NET Core versions, the @aspnet/signalr
npm package contains the JavaScript libraries. This package isn't included in the ASP.NET Core Web Application template. Use npm to obtain and install the @aspnet/signalr
npm package.
npm init -y
npm install @aspnet/signalr
The dependency on jQuery has been removed, however projects can still use jQuery.
ASP.NET Core SignalR doesn't support Microsoft Internet Explorer, whereas ASP.NET SignalR supports Microsoft Internet Explorer 8 or later. For more information, see ASP.NET Core SignalR supported platforms.
The JavaScript syntax has changed from the ASP.NET version of SignalR. Rather than using the $connection
object, create a connection using the HubConnectionBuilder API.
const connection = new signalR.HubConnectionBuilder()
.withUrl("/hub")
.build();
Use the on method to specify client methods that the hub can call.
The JavaScript syntax has changed from the ASP.NET version of SignalR. Rather than using the $connection
object, create a connection using the HubConnectionBuilder API.
const connection = new signalR.HubConnectionBuilder()
.withUrl("/hub")
.build();
Use the on method to specify client methods that the hub can call.
connection.on("ReceiveMessage", (user, message) => {
const msg = message.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
const encodedMsg = `${user} says ${msg}`;
console.log(encodedMsg);
});
After creating the client method, start the hub connection. Chain a catch method to log or handle errors.
connection.start().catch(err => console.error(err));
Hub proxies are no longer automatically generated. Instead, the method name is passed into the invoke API as a string.
Hub proxies are no longer automatically generated. Instead, the method name is passed into the invoke API as a string.
The Microsoft.AspNetCore.SignalR.Client NuGet package contains the .NET client libraries for ASP.NET Core SignalR.
Use the HubConnectionBuilder to create and build an instance of a connection to a hub.
connection = new HubConnectionBuilder()
.WithUrl("url")
.Build();
ASP.NET SignalR supports SQL Server and Redis. ASP.NET Core SignalR supports Azure SignalR Service and Redis.
ASP.NET Core повратне информације
ASP.NET Core је пројекат отвореног кода. Изаберите везу да бисте обезбедили повратне информације:
Догађаји
Поwер БИ ДатаВиз Светско првенство
14. феб 16 - 31. мар 16
Са 4 шансе за улазак, можете освојити конференцијски пакет и стићи до ЛИВЕ Гранд Финале у Лас Вегасу
Сазнајте вишеОбука
Модул
Replace client-side polling with ASP.NET Core SignalR - Training
In this module, you use ASP.NET Core SignalR to replace client-side polling functionality in an existing web app.
Документација
Overview of ASP.NET Core SignalR
Learn how the ASP.NET Core SignalR library simplifies adding real-time functionality to apps.
ASP.NET Core SignalR configuration
Learn how to configure ASP.NET Core SignalR apps.
ASP.NET Core SignalR .NET Client
Information about the ASP.NET Core SignalR .NET Client