.Net Core2.2:Swagger没有显示UI

问题描述 投票:0回答:1

我创建了一个空的dotnet API并将以下NuGet包添加到我的项目中:

<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1"/>

这是我的创业公司:

public class Startup {
    public Startup (IConfiguration configuration) {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices (IServiceCollection services) {
        services.AddMvc ().SetCompatibilityVersion (CompatibilityVersion.Version_2_2);
        services.AddSwaggerGen (c => {
            c.SwaggerDoc ("v1", new Info {
                Version = "v1",
                    Title = "My API",
                    Description = "My First ASP.NET Core Web API",
                    TermsOfService = "None",
                    Contact = new Contact () { Name = "Talking Dotnet", Email = "[email protected]", Url = "www.talkingdotnet.com" }
            });
        });
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure (IApplicationBuilder app, IHostingEnvironment env) {
        if (env.IsDevelopment ()) {
            app.UseDeveloperExceptionPage ();
        } else {
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts ();
        }

        app.UseHttpsRedirection ();
        app.UseMvc ();
        app.UseSwagger ();
        app.UseSwaggerUI (c => {
            c.SwaggerEndpoint ("/swagger/v1/swagger.json", "My API V1");
        });
    }
}

但Swagger没有显示它的UI,它看起来像这样:enter image description here

问题出在哪里?

.net-core swagger
1个回答
1
投票

您正在浏览json架构文件

你应该浏览Swagger UI

默认情况下它是https://youwebsite.com/swagger

这里是我使用的Swahbuckle设置的完整指南

Get started with Swashbuckle

© www.soinside.com 2019 - 2024. All rights reserved.