[英]ASP.NET CORE Don't have app.UseEndpoints() Method
Just learning ASP.NET Core now and in some guides I see app.UseEndpoints() method.现在刚刚学习 ASP.NET 核心,在一些指南中我看到了 app.UseEndpoints() 方法。
But when I created my ASP NET CORE Project I've only seen app.Run in StartUp.cs但是当我创建我的 ASP NET CORE 项目时,我只在 StartUp.cs 中看到了 app.Run
app.UseEndpoints(endpoints => { endpoints.MapHub<ChatHub>("/chat"); });
我怎样才能实现这个方法app.UseEndpoints(endpoints => { endpoints.MapHub<ChatHub>("/chat"); });
If you are using Net Core 2.1, you have to configure it that way:如果您使用的是 Net Core 2.1,则必须这样配置:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SignalRChat.Hubs;
namespace SignalRChat
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddSignalR();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseSignalR(routes =>
{
routes.MapHub<ChatHub>("/chat");
});
app.UseMvc();
}
}
}
Only afrer version 3.0 you can use app.UseEndpoints
只有在 3.0 版本之后,您才能使用app.UseEndpoints
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<ChatHub>("/chat");
});
See docs:请参阅文档:
If you're using .NET Core 3.1 version, then you need to make sure you've got:如果您使用的是 .NET Core 3.1 版本,那么您需要确保:
using Microsoft.AspNetCore.Builder;
In the file, and you'll need to be referencing (directly or indirectly) the Microsoft.AspNetCore.Routing
assembly.在文件中,您需要(直接或间接)引用Microsoft.AspNetCore.Routing
程序集。
If you are learning, you are better off starting with current .NET Core version, which is 3.1.如果您正在学习,最好从当前的 .NET Core 版本开始,即 3.1。 2.1 didn't have endpoint routing at all, work towards endpoint routing started in 2.2 but I think it was mostly behind the scenes, not exposed to consumer code as UseEndpoints()
. 2.1 根本没有端点路由,端点路由的工作始于 2.2,但我认为这主要是在幕后,没有像UseEndpoints()
那样暴露给消费者代码。 In 3.1, Sean's answer applies - you usually get the correct NuGet include just by specifying <Project Sdk="Microsoft.NET.Sdk.Web">
in your csproj.在 3.1 中,Sean 的答案适用 - 您通常只需在您的 csproj 中指定<Project Sdk="Microsoft.NET.Sdk.Web">
获得正确的 NuGet 包含。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.