【发布时间】:2019-11-24 08:51:02
【问题描述】:
正在为使用 AspNetCore 的 IIS 托管的 Web 应用程序设置 swagger。 .json 页面加载并且似乎可以很好地触及所有 API,但是当导航到 {localhost}/swagger 以查看 UI 页面时,我收到 404 错误。我在 Startup.cs 中有以下代码:
//Configure Services
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "API ", Version = "v1" });
c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
});
}
//Configure
app.UseSwagger();
app.UseStaticFiles();
app.UseDeveloperExceptionPage();
// Enable middleware to serve generated Swagger as a JSON endpoint.
// 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");
//c.RoutePrefix = string.Empty;
});
app.UseMvc();
}
有人发现这有什么潜在的问题吗?或者在故障排除方面有什么建议?现在已经在这方面工作了一段时间,希望有一双新的眼睛能看到我没有看到的东西。
【问题讨论】:
标签: c# asp.net-core swagger swagger-ui swashbuckle