C# 将Ocelot 16.0与ASP.Net Core 3.1集成不起作用,因为我需要将Swagger与Ocelot结合使用

C# 将Ocelot 16.0与ASP.Net Core 3.1集成不起作用,因为我需要将Swagger与Ocelot结合使用,c#,microservices,asp.net-core-webapi,api-gateway,ocelot,C#,Microservices,Asp.net Core Webapi,Api Gateway,Ocelot,我曾将Ocelot与Asp.Net Core 2.1及其工作模式一起使用,但与Asp.Net Core 3.1一起使用时,它根本不工作。在我看来,它并没有获取“ocelot.json”文件。以下是我的Program.cs文件: using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; usi

我曾将Ocelot与Asp.Net Core 2.1及其工作模式一起使用,但与Asp.Net Core 3.1一起使用时,它根本不工作。在我看来,它并没有获取“ocelot.json”文件。以下是我的Program.cs文件:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace ApiGateway
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration((hostingContext, config) =>
                {
                    config
                        .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
                        .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                        .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true)
                        .AddJsonFile($"ocelot.{hostingContext.HostingEnvironment.EnvironmentName}.json")
                        .AddEnvironmentVariables();
                })
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }
}
下面是ocelot.Development.json文件:

{
  "ReRoutes": [
    {
      "DownstreamPathTemplate": "/TestApi/api/test",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": "80"
        }
      ],
      "UpstreamPathTemplate": "/getTest"
    },
    {
      "DownstreamPathTemplate": "/TestMicroS/api/values",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": "82"
        }
      ],
      "UpstreamPathTemplate": "/getValues"
    }
  ],
  "GlobalConfiguration": {
    
  }
}
我已经从YouTube上引用了上述所有配置,但它不起作用。本地网站正在运行,但当我尝试点击上游路径时,它给了我localhost not found 404错误。请帮我解决这个问题


提前感谢。

尝试在JSON文件中将
重新路由重命名为
路由。

是。你说得对。Ocelot 16具有不同格式的配置文件。看这张照片。
{
  "ReRoutes": [
    {
      "DownstreamPathTemplate": "/TestApi/api/test",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": "80"
        }
      ],
      "UpstreamPathTemplate": "/getTest"
    },
    {
      "DownstreamPathTemplate": "/TestMicroS/api/values",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": "82"
        }
      ],
      "UpstreamPathTemplate": "/getValues"
    }
  ],
  "GlobalConfiguration": {
    
  }
}