How to open Swagger / index by default instead of Index.chtml

Viewed 427

When i start a project (.Net Core MVC), Index.chtml opens as usual. How to open Swagger interface by default.

I have default route like this:

app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
2 Answers

There's several ways you could achieve this:

  1. Change the Home Index action to HTTP redirect to your Swagger UI
  2. You can update the your Debug panel of the project's properties in Visual Studio to launch the Swagger UI page's URL instead of the root of your application.

Screenshot of Visual Studio Debug pane

You can achieve this using couple of ways:

  1. Open launchsettings.json file and change the value of the applicationUrl parameter to swagger url.

Or

  1. Add this route to RouteConfig.cs
    routes.MapHttpRoute(
        name: "swagger_root",
        routeTemplate: "",
        defaults: null,
        constraints: null,
        handler: new RedirectHandler((message => message.RequestUri.ToString()), "swagger"));

Or

  1. change Launch browser in project properties, Debug tab:

enter image description here

Related