Influenced by this answer to similar question, slightly modified code:
public class WebApiConfig
{
public static void Configure(IAppBuilder app)
{
var httpConfig = new HttpConfiguration();
// Attribute routing
config.MapHttpAttributeRoutes();
// Redirect root to Swagger UI
config.Routes.MapHttpRoute(
name: "Swagger UI",
routeTemplate: "",
defaults: null,
constraints: null,
handler: new RedirectHandler(SwaggerDocsConfig.DefaultRootUrlResolver, "swagger/ui/index"));
// Configure OWIN with this WebApi HttpConfiguration
app.UseWebApi(httpConfig);
}
}
This way it is not necessary to create new WebAPI controller as so did @bsoulier in his answer.
This solution is based on already existing class RedirectHandler
in Swashbuckle.Core
assembly.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…