路由声明它在 system.web 中定义但未找到错误

5 c# asp.net .net-framework-version

当我从 .netframework 迁移到 .net core 时,我在 .netcore 3.1 中遇到了这个错误,我 这里点击了这个链接但仍然无法解决这个问题。

 public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();

            // Web API configuration and services
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}"
            );

            config.Routes.MapHttpRoute(
                name: "DefaultApiWithActionApi",
                routeTemplate: "api/{controller}/{action}"
            );

            // Configure formatting settings
            ConfigureFormatting(config);

            // Add Global Exception Handling and Logging
            config.Services.Replace(typeof(IExceptionHandler), GlobalExceptionHandler.GetInstance());
            config.Services.Replace(typeof(IExceptionLogger), new GlobalExceptionLogger());
        }
Run Code Online (Sandbox Code Playgroud)

严重性代码描述项目文件行抑制状态错误 CS7069 对类型“Route”的引用声称它在“System.Web”中定义,但找不到 WorkerRole

是他们的替代网络,所以更改它会删除我的错误,它的工作原理类似。

任何建议都被接受。

Roh*_*hav 0

它看起来像 .NET 框架中的配置文件,要在 .NET core 3.1 中实现此目的,您应该在 .net core 的startup.cs 文件中添加配置。

例如在startup.cs文件的configure方法中

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseRouting();
            // global cors policy
            app.UseCors(x => x
                .AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader());
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Run Code Online (Sandbox Code Playgroud)