Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

});
like image 736
jude camp Avatar asked Oct 20 '25 17:10

jude camp


1 Answers

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"
     }
}
like image 194
spaleet Avatar answered Oct 23 '25 07:10

spaleet