Reputation: 2223
I have Web API 2 and configured Swagger using [Swashbuckle][1] as such:
private static void ConfigureSwagger(HttpConfiguration config)
{
// add the versioned IApiExplorer and capture the strongly-typed implementation (e.g. VersionedApiExplorer vs IApiExplorer)
// note: the specified format code will format the version as "'v'major[.minor][-status]"
var apiExplorer = config.AddVersionedApiExplorer(o => o.GroupNameFormat = "'v'VVV");
config
.EnableSwagger(swagger =>
{
// build a swagger document and endpoint for each discovered API version
swagger.MultipleApiVersions(
(apiDescription, version) => apiDescription.GetGroupName() == version,
info =>
{
foreach (var group in apiExplorer.ApiDescriptions)
{
var description = "AAAA API.";
if (group.IsDeprecated)
{
description += " This API version has been deprecated.";
}
info.Version(group.Name, $"AAAA API {group.ApiVersion}")
.Contact(c => c.Name("AAAA").Email("[email protected]"))
.Description(description)
.License(l => l.Name("AAAA").Url("www.AAAA.com"))
.TermsOfService("AAAA. All rights reserved.");
}
});
// add a custom operation filter which sets default values
swagger.OperationFilter<SwaggerDefaultValues>();
// integrate xml comments
swagger.IncludeXmlComments(XmlCommentsFilePath);
//swagger.RootUrl(req => SwaggerDocsConfig.DefaultRootUrlResolver(req) + "/api");
})
.EnableSwaggerUi(swagger => swagger.EnableDiscoveryUrlSelector());
}
When running locally everything is working fine I can see swagger page with api endpoints. Now when we deploy this into our IIS under Default Web Site\AAAA the path is always being resolved to the root of the Default Web Site and not AAAA (WebAPI) application
Does anyone know what could be the issue?
Upvotes: 0
Views: 3301
Reputation: 2223
Answer from here.
OWIN Hosted in IIS - Incorrect VirtualPathRoot Handling When you host Web API 2 on top of OWIN/SystemWeb, Swashbuckle cannot correctly resolve VirtualPathRoot by default.
You must either explicitly set VirtualPathRoot in your HttpConfiguration at startup, or perform customization like this to fix automatic discovery:
httpConfiguration.EnableSwagger(c =>
{
c.RootUrl(req =>
req.RequestUri.GetLeftPart(UriPartial.Authority) +
req.GetRequestContext().VirtualPathRoot.TrimEnd('/'));
}
Upvotes: 3