Swagger run locally but not on IIS, not resolving base path
Try using a relative path:
setupAction.SwaggerEndpoint("../swagger/Imaging4CastApiSpecification/swagger.json", "4Cast API");
Please note answer and explanation from the following issue: SwashBuckle
Here is my Swagger config for once of PRD application. Hope it helps
public static IServiceCollection AddSwaggerConfig(this IServiceCollection services, IHostingEnvironment env, string title, string version) => services.AddSwaggerGen(c => { //Ensure XML Document File of project is checked for both Debug and Release mode c.IncludeXmlComments("Your App.xml"); //Display Enum name c.DescribeAllEnumsAsStrings(); //c.OperationFilter<AddRequiredHeaderParameter>(); //Authentication for Bearer c.AddSecurityDefinition("Bearer", new ApiKeyScheme { In = "header", Description = "Please enter JWT with Bearer into field", Name = "Authorization", Type = "apiKey" }); c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>> { {"Bearer", Enumerable.Empty<string>()} }); c.SwaggerDoc(version, new Info { Title = title, Version = version, Description = "", Contact = new Contact { Email = "Support@ABC.com", Name = "" } }); });
Startup file
app. //Swagger .UseSwagger() .UseSwaggerUI(c => { c.SwaggerEndpoint($"./{_version}/swagger.json", Title); });
The version is app variable from Config file which will be filtered by CI/CD
Swagger does not support Virtual Directory by default. Try and add this to your Startup.cs
app.UseSwagger(c => { c.RouteTemplate = "virtual_path/{documentName}/swagger.json"; }); app.UseSwaggerUI(c => { //Include virtual directory c.RoutePrefix = "virtual_path";// add your virtual path here. c.SwaggerEndpoint("v1/swagger.json", "Api v1"); });