In my ASP 4.6 application I have:
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Feature Toggle API V1"); });
When I run it on localhost:5000/swagger/v1/swagger.json
it works fine but when I deploy it on a remote server that uses virtual directories for different applications someserver/myapp/swagger/v1/swagger.json
it doesn't work.
What is the best practice in turning app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Feature Toggle API V1"); });
to a relative path that works on localhost as well as within a virtual directory?
I was with this same problem Try this:
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("v1/swagger.json", "V1 Docs");
});
Maybe this question is a bit old, but I had the same problem and found the answer in the ASP.NET Core documentation:
If using directories with IIS or a reverse proxy, set the Swagger endpoint to a relative path using the ./ prefix. For example, ./swagger/v1/swagger.json. Using /swagger/v1/swagger.json instructs the app to look for the JSON file at the true root of the URL (plus the route prefix, if used). For example, use http://localhost://swagger/v1/swagger.json instead of http://localhost:///swagger/v1/swagger.json.
Original link: https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-2.2&tabs=visual-studio
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With