SignalR在ASP.Net Core~1.1中

时间:2017-04-03 09:54:34

标签: node.js signalr .net-core

我想在Asp.Net Core 1.1中创建实时应用程序,但我不能再使用在我的应用程序中,帮助我选择哪种框架对我来说更好?我必须选择或MicroSoft为我们提供解决方案吗?我可以使用类似于的替代框架吗? !

  

Microsoft.AspNetCore版本1.1.1   Microsoft.AspNetCore.Mvc版本1.1.1

3 个答案:

答案 0 :(得分:4)

  1. https://dotnet.myget.org/f/aspnetcore-ci-dev/api/v3/index.json添加到可用的包源(工具/选项/ NuGet包管理器/包源)
  2. 安装Microsoft.AspNetCore.SignalR.Server软件包版本0.2.0-preview2-22683。您可能需要调整“包源”并选中NuGet包管理器中的“包含预发布”复选框,以查看搜索结果中的包。
  3. 安装Microsoft.AspNetCore.WebSockets包(版本1.0.1)。
  4. 添加services.AddSignalR(),app.UseWebSockets()和app.UseSignalR()调用Startup.cs。
  5. 适用于Visual Studio 2017和.NET Core 1.1.1。

答案 1 :(得分:1)

仅供参考https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json(1.0.0 *)中的信号器包现在仅针对.NETStandard,Version = v2.0平台。

可以在存储库中找到ASP.NET Core 1.1的旧软件包(0.2.0 *) https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json

答案 2 :(得分:0)

似乎你现在可以在ASP.NET Core 1.1应用程序中使用SignalR 2,只要它们针对完整的.NET框架而不是.NET核心。

为此,您需要为OWIN创建一个Middleware-Wrapper。 Yatajgaa nice sample over at MSDN

这是有趣的部分(取自上述样本):

using Microsoft.Owin.Builder; 
using Owin; 
using System; 
using System.Collections.Generic; 
using System.Threading.Tasks; 
using Microsoft.AspNetCore.Builder; 

namespace RealTimeDataEditor 
{
    using AppFunc = Func<IDictionary<string, object>, Task>; 
 
    public static class BuilderExtensions 
    { 
        public static IApplicationBuilder UseAppBuilder( 
            this IApplicationBuilder app,  
            Action<IAppBuilder> configure) 
        { 
            app.UseOwin(addToPipeline => 
            { 
                addToPipeline(next => 
                { 
                    var appBuilder = new AppBuilder(); 
                    appBuilder.Properties["builder.DefaultApp"] = next; 

                    configure(appBuilder); 

                    return appBuilder.Build<AppFunc>(); 
                }); 
            }); 
            return app; 
        }
        public static void UseSignalR2(this IApplicationBuilder app) 
        {
            app.UseAppBuilder(appBuilder => appBuilder.MapSignalR()); 
        }
    }
}

这样你就可以在Startup.cs文件中的Configure()方法中调用app.UseSignalR2();

免责声明:SignalR 2尚未针对ASP.NET Core开发,因此在生产中使用时可能会出现一些问题。