如何在aspnetcore 2.0.0预览中使用SignalR

时间:2017-06-05 22:57:10

标签: asp.net-core-mvc signalr-2

我正在尝试使用带有aspnetcore 2.0.0预览版的SignalR。根据发行说明,预览版应该支持signalR,我可以添加对“Microsoft.aspnetcoreSignalR”包的引用。
但是,我无法在IApplicationBuilder上找到MapSignalR扩展方法或类似useSignalR()的内容。
谷歌搜索这个提供了很多UseAppBuilder扩展方法的例子。但是,我仍然卡在MapSignalR下面的代码:

using Microsoft.AspNetCore.Builder;

using Microsoft.Owin.Mapping;
using Microsoft.Owin.Helpers;
using Microsoft.Owin.Extensions;
using Microsoft.Owin.Builder;
using Owin;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace MyNamespace
{
    using AppFunc = Func<IDictionary<string, object>, Task>;

    public static class SignalRExtensions
    {


        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());
        }
    }
}

无法找到MapSignalR扩展名方法。如果我能找到一些可以与aspnetcore一起使用的nuget包的任何想法?或者是否有一种不同的机制来使用aspnetcore 2.0.0预览初始化signalR? 我正在使用Visual Studio 2017预览版15.3,安装了.Net core 2.0预览版。

1 个答案:

答案 0 :(得分:1)

我基本上有一组错误的引用。如果我只有aspnetcore 2.0.0预览版1和相应的Microsoft.aspnetcore.signalR 1.0.0预览版软件包,那么$(document).on("click", ".edit_text", function() { // search for an 'input' element within the context of the clicked element // .length will be > 0 if any are found if( $('input', this).length ) { $(this).html("<input type='text'>") } }); 已经有"date Thursday June 03 12:02:56 2017" 方法作为 <?php if (isset($_POST['numb']) && isset($_POST['email1'])) { $error = false; $numb = $_POST['numb']; for ($i = 1; $i <= $numb; $i++) { if (!isset($_POST['email' . $i])) { $error = true; } } if ($error == false) { include 'config.php'; try { $connection = new PDO($dsn, $user, $pass); $suc1 = true; } catch (PDOException $e) { echo $e->GetMessage(); $suc1 = false; } if ($suc1 == true) { $sql = "INSERT INTO alunos(email, emailKey) VALUES "; for ($i = 1; $i <= $numb; $i++) { $BAMBAM[$i] = '(:email' . $i . ', :emailkey' . $i . ')'; $FELIPEFRANCO[$i] = sha1(microtime() . $_POST['email'. $i]); if ($i != $numb) { $BAMBAM[$i] = $BAMBAM[$i] . ','; } $sql = $sql . $BAMBAM[$i]; } $insert = $connection->prepare($sql); for ($i = 1; $i <= $numb; $i++) { $param1 = 'email' . $i; $value1 = $_POST['email' . $i]; $param2 = 'emailkey' . $i; $value2 = $FELIPEFRANCO[$i]; echo '<script>alert("' . $param1 . ' -> ' . $value1 . '")</script>'; $insert->bindParam($param1, $value1, PDO::PARAM_STR); $insert->bindParam($param2, $value2, PDO::PARAM_STR); } try { $insert->execute(); $suc2 = true; } catch (PDOException $e) { echo $e->GetMessage(); $suc2 = false; } echo $sql; } else { header('Location: addAlunosForm.php?error=internal'); } } else { header('Location: addAlunosForm.php?error=fill'); } } else { header('Location: addAlunosForm.php?error=fill'); } ?> 的扩展方法,我们不会需要以上任何代码。