Search code examples
swaggerasp.net-core-webapiswagger-ui

How to load a view by default instead of Swagger UI?


I'm working on a .NET 6 web api and I've configured the Program.cs to use Swagger UI when in development mode. How can I change this so that I still have access to Swagger UI but by default load the default view?

For example, when I run my project, it loads https://localhost:7004/swagger/index.html instead I want to load https://localhost:7004 but still have access to https://localhost:7004/swagger/index.html

Current Program.cs:

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseStaticFiles();
app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();
app.MapControllerRoute(
    name: "default",
    pattern: "{controller=ControllerName}/{action=Index}/{id?}");

Solution

  • Open your project's priperties (screenshot below -)

    Project properties

    Under the 'Debug'section, click on 'Open debug launch profiles UI'. This should open the UI shown below -

    Debug section of project properties dialog box

    Remove the text 'swagger', leave it blank, restart your application. This should navigate to -

    Remove 'Swagger' from project properties dialog box.

    Note that you can still enter full path to swagger link to navigate to it -

    Navigation to swagger page