.net6 中 WebAPI 发布后 Swagger 不显示
1、发布后请求 https://localhost:5001/swagger/index.html
发生404错误,如下图所示:
2、原因:
Net 6 在创建 Web API 时可以直接选择 Swagger,在开发环境下Debug或Release没有问题,在发布后发现打不开swagger。
// Configure the HTTP request pipeline.if(app.Environment.IsDevelopment())// 判断在开发环境中才加载{}app.UseSwagger();//版本切换app.UseSwaggerUI();之前的代码会判断在开发环境中才加载,移出去之后就都可以加载Swagger了。