简体   繁体   English

ASP.NET CORE 没有 app.UseEndpoints() 方法

[英]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

  1. So Need I install some utilities for this or UseEndPoints was removed?那么我需要为此安装一些实用程序还是删除 UseEndPoints ?
  2. How Can I realize this method 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:请参阅文档:

ASP.NET Core 2.1 ASP.NET 内核2.1

ASP.NET Core 3.0 + ASP.NET 内核 3.0 +

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.

相关问题 在 ASP.NET Core 中使用 app.Run 和 app.UseEndpoints 有什么区别? - What are the difference using app.Run and app.UseEndpoints in ASP.NET Core? 如何在 app.UseEndPoints 中将自定义路由操作作为委托实例添加到 ASP.NET Core 3.1 应用程序? - How to add custom routed action as a delegate instance to ASP.NET Core 3.1 app in app.UseEndPoints? 具有 asp.net 核心 3 UseEndpoints 的多个 controller 路由模式 - Multiple controller route patterns with asp.net core 3 UseEndpoints 选择标签ASP.NET Core没有项目 - Select tag ASP.NET Core don't have items app.UseRouting() 和 app.UseEndPoints() 有什么区别? - What are the differences between app.UseRouting() and app.UseEndPoints()? 为什么在多次调用 app.UseEndpoints(..) 时不执行中间件? - Why is middleware not executed when there are multiple calls to app.UseEndpoints(..)? 为什么asp.net core UseEndpoints context.Request.RouteValues[&quot;key&quot;] 没有值 - Why asp.net core UseEndpoints context.Request.RouteValues["key"] no value ASP.NET Core WebAPI 崩溃是因为我没有 StaticFileMiddleware? - ASP.NET Core WebAPI crashes because I don't have StaticFileMiddleware? .css 根文件夹中的文件不会加载到 ASP.NET Core MVC web 应用程序中的 _Layout 中 - .css files in root folder don't load in _Layout in ASP.NET Core MVC web app asp.net core 3 axios 不按预期发帖 - asp.net core 3 axios don't post as expected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM