gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 08:31:15 24 4
gpt4 key购买 nike

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

最佳答案

根据您的评论,您的目标是 .NET Core 2.1,但是 the UseEndpoints extension method was introduced in 3.0 .

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

像这样:

app.UseSignalR(route =>
{
route.MapHub<MyHub>("/myHub");
});

关于asp.net-core - IApplicationBuilder 不包含定义 UseEndpoints。 app.UseEndpoints(...) 不适用于 ASP.NET CORE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59578416/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com