【问题标题】:Swagger with .net core 3.1 and LambdaSwagger 与 .net core 3.1 和 Lambda
【发布时间】:2022-06-30 05:00:07
【问题描述】:

我正在为我们的 API 使用 .net core 3.1 和 swashbuckle swagger。 在本地这可以正常工作,当我运行我的项目时,它会很好地加载以下内容: https://localhost:44352/swagger/index.html 和我所有的 api 端点。

当我部署到服务器时,相同的代码在导航到 /swagger/index.html 时显示没有错误的空白屏幕。不知道在哪里查看。以下是我的代码:

public void ConfigureServices(IServiceCollection services)
 {
    services.AddCors();
    services.AddMvc(options => options.EnableEndpointRouting = false);
    services.AddControllers()
        .AddNewtonsoftJson();
    services.AddSwaggerGen(c =>
    {
        c.SwaggerDoc("v1", new OpenApiInfo
        {
            Title = "API",
            Version = "V1",
            Description = ""
        });
    }); 
 }
 
 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
 {
    app.UseMvc();
    app.UseSwagger();

    app.UseSwaggerUI(c =>
    {
        c.SwaggerEndpoint("/swagger/v1/swagger.json", "API");
    });
 }

请输入任何内容。谢谢

【问题讨论】:

  • 将您的SwaggerEndpoint 名称与SwaggerDocs 的标题和版本相匹配,因此应该是API V1 而不是API

标签: c# .net asp.net-core swagger swashbuckle


【解决方案1】:
public readonly IWebHostEnvironment _env;
    public readonly AppDbContext _context;

    public HeroController(IWebHostEnvironment env, AppDbContext context)
    {
        _env = env;
        _context = context;
    }
index - public ActionResult Index()
    {
        List<Hero> heroList = _context.hero.ToList();
        return View(heroList);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-01
    • 1970-01-01
    • 2021-05-31
    • 2020-04-10
    • 2021-11-25
    • 2023-03-25
    相关资源
    最近更新 更多