0

How can I add a base url on swagger ui like this in C#. enter image description here

Please refer the below screenshot what I actually needed in which manner. enter image description here

2 Answers2

0

Have you tested this?

app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "API V1");
});
Hossein Sabziani
  • 1
  • 2
  • 15
  • 20
  • Tried this but not getting the exact result. I want something like this "Base Url : example.com" – Avanish Feb 16 '23 at 15:29
0

If you want to add "mycoolapi" to the beginning of your default swagger UI URL, like this: http:///mycoolapi/swagger, then do the following:

In your Startup.cs Configure method:

app.UseSwagger(c =>
{
    c.RouteTemplate = "mycoolapi/swagger/{documentname}/swagger.json";
});


app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/mycoolapi/swagger/v1/swagger.json", "My Cool API V1");
    c.RoutePrefix = "mycoolapi/swagger";
});

Then, if you currently have your launchSettings to launch browser at swagger UI upon startup (for development purposes), update your launchSettings.json file profiles section similarly:

"profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "mycoolapi/swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "MyProject.Web": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "mycoolapi/swagger",
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }