我从Swashbuckle开始,我在带有Swashbuckle的.NET Core中创建了Web API。 我需要在IIS站点的子应用程序中部署我的API
IIS站点(站点)
我希望通过此url访问swagger UI:
http://ip:80/myApi/swagger
我希望通过此url访问方法:
http://ip:80/myApi/api/[controller]/methode
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info { Title = "My REST API", Version = "v1" });
});
if (env.IsEnvironment("ProdIT"))
{
app.UseSwagger(c =>
{
c.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.BasePath = "/myApi/");
c.RouteTemplate = "myApi/api-docs/{documentName}/swagger.json";
});
app.UseSwaggerUI(c =>
{
c.RoutePrefix = "myApi/swagger";
c.SwaggerEndpoint("/myApi/api-docs/v1/swagger.json", "MY REST API V1");});
[Route("api/[controller]")]
您能告诉我代码有什么问题吗?
预先感谢
答案 0 :(得分:2)
我遇到了同样的问题,我通过像这样配置SwaggerUI来解决了这个问题;
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("v1/swagger.json", "MY REST API V1");});
}