I have a WebApi project with Swashbuckle installed onto it.
In default setup, I must open in browser http://localhost:56131/swagger/ui/index
to view my operations description and test page. I want it to be accessible from root of the site: http://localhost:56131/
. How can I achieve this?
Influenced by this answer to similar question, slightly modified code:
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
inSwashbuckle.Core
assembly.For
.net core
in the properties launchsettings.json modify profiles and api sections to point to swagger.If you for sure use a Web API project, you can:
Note the use of
ApiExplorerSettings
attribute, so that it doesn't show up in the Swagger definition.Even simpler variant of the above answer:
The simpler, the better! This one works for me.
Change the value of
launchUrl = "swagger/index.html"
in launchSetting.Json in asp.net core 2.1/2.2if the task allows you, in _layout.chtml just add follow line to head:
<meta http-equiv="refresh" content="0; URL='/swagger'" />
this will redirect you on swagger/index after page was loaded