【问题标题】:SignalR In ASP.Net Core ~1.1 [closed]ASP.Net Core 中的 SignalR ~1.1 [关闭]
【发布时间】:2017-06-29 14:51:03
【问题描述】:

我想在 Asp.Net Core 1.1 中创建实时应用程序,但我不能再在我的应用程序中使用,请帮我选择什么框架对我来说更好?我必须选择 或者微软有解决方案吗?我可以使用类似于 的替代框架吗? !

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

【问题讨论】:

    标签: signalr node.js signalr node.js signalr .net-core


    【解决方案1】:
    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. 向 Startup.cs 添加 services.AddSignalR()、app.UseWebSockets() 和 app.UseSignalR() 调用。

    适用于 Visual Studio 2017 和 .NET Core 1.1.1。

    【讨论】:

      【解决方案2】:

      仅供参考,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

      【讨论】:

        【解决方案3】:

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

        为此,您需要为 OWIN 创建一个中间件包装器。 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 开发,因此在生产中使用它时可能会出现一些问题。

        【讨论】:

        • 感谢您的回答,但此解决方案仅适用于 ASPNETCORE.NET462。并且不适用于 ASPNETCORE.NETCORE:(youtube.com/watch?v=wIsync6vTfQ
        • 是的,这就是我在第一句话中所说的 ;-) 但是,如果您打算在 Windows 硬件上运行,这可能是最简单的解决方案。
        猜你喜欢
        • 2017-07-21
        • 2017-11-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-15
        • 2018-12-07
        相关资源
        最近更新 更多