Mariusz Jamro Mariusz Jamro - 1 year ago 391
ASP.NET (C#) Question

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

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


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

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

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

Answer Source

The UseSwaggerUi() extension method to enable the middleware in the Configure method of the StartUp class takes two variables. A baseRoute which is on swagger/ui by default, and swaggerUrl which is on swagger/v1/swagger.json by default. Simply provide a different baseRoute.

//Swagger will be available under '/api' url

If people would like to learn more about configuring Swagger for ASP.NET Core, I've written a blogpost to get started:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download