Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?}");
            });
like image 775
Mccree Avatar asked Oct 15 '25 18:10

Mccree


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

like image 190
Martin Costello Avatar answered Oct 18 '25 06:10

Martin Costello


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

like image 34
MasLoo Avatar answered Oct 18 '25 08:10

MasLoo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!