How to set swagger as start page https://localhost:44321/swagger/index.html to https://localhost:44321/swagger set as the default page?
This is my code in IApplicationBuilder:
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.UseSwagger();
app.UseSwaggerUI(c =>
{
string clientId = Configuration["Swagger:ClientId"];
c.SwaggerEndpoint("/swagger/v1/swagger.json", "aims_api v1");
c.OAuthClientId(clientId);
c.OAuthAppName("Azure AD API");
c.OAuthScopeSeparator(" ");
});
In launchSettings.json change launchUrl to swagger :
"ProjectName": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
And if you want to customize the default swagger url :
Change the RoutePrefix :
app.UseSwaggerUI(c =>
{
//...
c.RoutePrefix = "myapi/swagger";
});
And change the launchSettings.json :
"ProjectName": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"launchUrl": "myapi/swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
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