'how to set swagger as start page in dotnet core

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(" ");               

        });

        


Solution 1:[1]

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"
     }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Almost