gpt4 book ai didi

c# - Swagger 不工作 Asp.net Core 如何打开 swagger ui

转载 作者:行者123 更新时间:2023-12-04 00:55:02 27 4
gpt4 key购买 nike

这是我的 Startup.cs 文件
这是我在 Startup.cs 中的 ConfigureService 方法我已经完全根据文档对其进行了修改但它不起作用我已经删除了启动网址所以它只是在端口上并且我没有设置任何路由我在他的帮助下遇到了麻烦受到赞赏

  public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddControllers();
services.ConnectionToACQEs(Configuration);
services.AddAutoMapper(typeof(Startup));
// Register the Swagger generator, defining 1 or more Swagger documents
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Version = "v1",
Title = "ToDo API",
Description = "A simple example ASP.NET Core Web API",
TermsOfService = new Uri("https://example.com/terms"),
Contact = new OpenApiContact
{
Name = "Nicky Liu",
Email = "nicky@zedotech.com",
Url = new Uri("https://www.zedotech.com"),
},
License = new OpenApiLicense
{
Name = "Use under LICX",
Url = new Uri("https://example.com/license"),
}
});
});
}

这是我的配置方法
     public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//if (env.IsDevelopment())
//{
// app.UseDeveloperExceptionPage();
//}


/// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
//app.UseHttpsRedirection();

app.UseRouting();

//app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});



}

最佳答案

 app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
c.RoutePrefix = "";
});
enter image description here
右键单击您的项目并在左侧面板上选择调试,然后在您的浏览器(绝对或相关 URL)上将其留空。

关于c# - Swagger 不工作 Asp.net Core 如何打开 swagger ui,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63159906/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com