这是我的 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 = "";
});
右键单击您的项目并在左侧面板上选择调试,然后在您的浏览器(绝对或相关 URL)上将其留空。
关于c# - Swagger 不工作 Asp.net Core 如何打开 swagger ui,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63159906/