【问题标题】:Route claim it is defined in system.web but it not found error路由声明它在 system.web 中定义,但未找到错误
【发布时间】:2020-05-24 07:59:22
【问题描述】:

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

 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());
        }

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

是他们的备用网络,所以更改它会消除我的错误,它的工作方式类似。

接受任何建议。

【问题讨论】:

  • 那些看起来像 ASP.NET WebAPI 类型,而不是 ASP.NET Core 类型...

标签: c# asp.net .net-framework-version


【解决方案1】:

它看起来像 .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();
            });
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-23
    • 2018-09-12
    • 1970-01-01
    • 1970-01-01
    • 2019-02-21
    • 2020-07-23
    • 2019-12-04
    • 2021-02-24
    相关资源
    最近更新 更多