Mccree
Mccree

Reputation: 113

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

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?}");
            });

Upvotes: 4

Views: 1466

Answers (2)

itsMasoud
itsMasoud

Reputation: 1375

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

Upvotes: 1

Martin Costello
Martin Costello

Reputation: 10872

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

Upvotes: 2

Related Questions