How to change base url of Swagger in ASP.NET core

Mariusz Jamro picture Mariusz Jamro · Aug 24, 2016 · Viewed 40.5k times · Source

By default when you enable swagger in ASP.NET Core project it's available on url:

http://localhost:<random_port>/swagger/ui

I would like to use a different base url instead of /swagger/ui. How/where can i configure that?

I found that for older versions you can configure the RootUrl but there aren't similiar method in ASP.NET Core:

.EnableSwagger(c =>
{
    c.RootUrl(req => myCustomBasePath);
});

Answer

maxspan picture maxspan · Apr 27, 2017

The new swagger version provides you with a property called RoutePrefix.

app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
    c.RoutePrefix = "docs";
});

Should work for .net core