IApplicionBuilder 不包含定义 UseEndpoints。app.UseEndpoints(...) 在 ASP.NET CORE 上不起作用

Ter*_*ves -1 signalr asp.net-core

我正在尝试将 signalR 合并到我的项目中,但是当我尝试使用 app.UseEndpoints(...) 时,它给了我一个错误,指出“IApplicationBuilder 不包含 UserEndpoints。这是我的 StartUp 类上的代码:

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {


        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }


        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseCookiePolicy();

        app.UseAuthentication();

        //SIGNAL R - ERROR
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapHub<ChatHub>("/myHub");
        });



        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

我的枢纽:

 public class MyHub : Microsoft.AspNet.SignalR.Hub
   {
    public async Task PostMarker(string latitude, string longitude) 
    {
        await Clients.All.SendAsync("ReceiveLocation", latitude, longitude);
    }
}
Run Code Online (Sandbox Code Playgroud)

Jim*_*utt 10

根据你的意见,你的目标.NET 2.1的核心,但UseEndpoints在3.0中引入的扩展方法

要在 2.1 中添加 SignalR,首先要确保你services.AddSignalR();ConfigureServices方法中有。其次,你应该app.UseSignalRConfigure方法中使用,而不是UseEndpoints.

像这样:

app.UseSignalR(route =>
{
    route.MapHub<MyHub>("/myHub");
});
Run Code Online (Sandbox Code Playgroud)