我有一只Asp。Net core 2.2项目。

最近,我把。net core 2.2版本改成了。net core 3.0 Preview 8。在这个更改之后,我看到这个警告消息:

使用'UseMvc'配置MVC时,使用端点是不支持的 路由。要继续使用“UseMvc”,请设置 “MvcOptions。EnableEndpointRouting = false' inside 'ConfigureServices'。

我明白,通过设置EnableEndpointRouting为false,我可以解决这个问题,但我需要知道解决它的正确方法是什么,以及为什么端点路由不需要UseMvc()函数。


当前回答

端点路由在ASP上默认是禁用的。NET 5.0

只需在启动中配置

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc(options => options.EnableEndpointRouting = false);
    }
    

这对我很有效

其他回答

使用以下代码

app.UseEndpoints(endpoints =>
            {
                endpoints.MapDefaultControllerRoute();
                endpoints.MapGet("/", async context =>
                {
                    await context.Response.WriteAsync("Hello World!");
                });
            });

—>在“ConfigureServices”方法中

        //*****REGISTER Routing Service*****
        services.AddMvc();
        services.AddControllers(options => options.EnableEndpointRouting = false);

-配置方法中的>—Startup.cs

       //*****USE Routing***** 
        app.UseMvc(Route =>{
            Route.MapRoute(
                name:"default",
                template: "{Controller=Name}/{action=Name}/{id?}"
            );
        });

这对我来说是有效的(在Startup.cs > ConfigureServices方法中添加):

services.AddMvc(option => option.EnableEndpointRouting = false)

你可以使用: 在ConfigureServices方法中:

services.AddControllersWithViews();

配置方法:

app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
        });

这对我很有效

 services.AddMvc(options => options.EnableEndpointRouting = false); or 
 OR
 services.AddControllers(options => options.EnableEndpointRouting = false);