Close

Swagger StartUp page

Let’s say you create an Azure Web App using ASP.Net Core 2.2 and you want to show the Swagger page when someone calls the REST service via the base URL. There’s just two easy steps to do that.

Under Properties you will find a json file launchSettings. Comment out setting launchUrl so that no specific webservice method is called:

  "iisSettings": {
    "windowsAuthentication": false, 
    "anonymousAuthentication": true, 
    "iisExpress": {
      "applicationUrl": "http://localhost:49645",
      "sslPort": 44335
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
     // "launchUrl": "v1.0/customers/CitoBV",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "CustomerService": {
      "commandName": "Project",
      "launchBrowser": true,
      //"launchUrl": "v1.0/customers/CitoBV",
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

Next open your Startup.cs file and set the RoutePrefix to an empty string.

app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "CustomerService v1.0");
                c.RoutePrefix = "";
             
            });