IApplicationBuilder 不包含 UseEndpoints 定义。 app.UseEndpoints(...) 不适用于 ASP.NET CORE

问题描述 投票:0回答:1

我正在尝试将 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?}");
        });
    }
}

我该怎么办?

我的中心:

 public class MyHub : Microsoft.AspNet.SignalR.Hub
   {
    public async Task PostMarker(string latitude, string longitude) 
    {
        await Clients.All.SendAsync("ReceiveLocation", latitude, longitude);
    }
}
asp.net-core signalr netcoreapp2.1
1个回答
11
投票

根据您的评论,您的目标是.NET Core 2.1,但是

UseEndpoints
扩展方法是在3.0中引入的

要在 2.1 中添加 SignalR,首先确保您的

services.AddSignalR();
方法中有
ConfigureServices
。其次,您应该在
app.UseSignalR
方法中使用
Configure
,而不是
UseEndpoints

像这样:

app.UseSignalR(route =>
{
    route.MapHub<MyHub>("/myHub");
});
© www.soinside.com 2019 - 2024. All rights reserved.