6

ASP.NET Core Web API project is configured with Swagger. When I run the project on my local machine the launchUrl works correctly and automatically redirects to my Swagger apidocs location (https://localhost:44373/apidocs/index.html)

But as soon as I publish the project on Azure the launchUrl no longer works correctly. (https://myapiurl.com) => Should'nd this redirect automatically to (https://myapiurl.com/apidocs/index.html) ?

What am I missing for the published environment?

{
    "iisSettings": {
        "windowsAuthentication": false,
        "anonymousAuthentication": true,
        "iisExpress": {
            "applicationUrl": "http://localhost:60837",
            "sslPort": 44373
        }
    },
    "$schema": "http://json.schemastore.org/launchsettings.json",
    "profiles": {
        "IIS Express": {
            "commandName": "IISExpress",
            "launchBrowser": true,
            "launchUrl": "apidocs",
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Production"
            }
        },
        "Web.Apis.Organization": {
            "commandName": "Project",
            "launchBrowser": true,
            "launchUrl": "apidocs",
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "applicationUrl": "https://localhost:5001;http://localhost:5000"
        }
    }
}

My COnfigure Method

app.UseStaticFiles();

            // Enable middle-ware to serve generated Swagger as a JSON endpoint. https://github.com/domaindrivendev/Swashbuckle.AspNetCore#generate-multiple-swagger-documents
            app.UseSwagger(options =>
            {
                options.RouteTemplate = "apidocs/{documentName}/apispec.json";
            });

            //Enable middle-ware to serve swagger - ui(HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
            // https://dejanstojanovic.net/aspnet/2018/november/setting-up-swagger-to-support-versioned-api-endpoints-in-aspnet-core/
            // https://github.com/microsoft/aspnet-api-versioning/issues/516
            app.UseSwaggerUI(c =>
            {
                c.RoutePrefix = "apidocs";

                //Build a swagger endpoint for each discovered API version
                foreach (var apiDescription in apiVersionProvider.ApiVersionDescriptions)
                {
                    c.SwaggerEndpoint($"/{c.RoutePrefix}/{apiDescription.GroupName}/apispec.json", $"Version { apiDescription.ApiVersion.ToString()}");
                }

                c.DisplayRequestDuration();

                c.DocumentTitle = GlobalConstants.OrganizationFullName;

                // Custom Index
                c.IndexStream = () => GetType().Assembly.GetManifestResourceStream("Web.Apis.Organization.wwwroot.swagger_ui.index.html");

                // Custom style
                //c.InjectStylesheet("/swagger-ui/custom.css");
                //c.InjectJavascript("/swagger-ui/custom.js");
            });
ameya
  • 1,448
  • 1
  • 15
  • 31
  • No, it shouldn't redirect automatically! `https://myapiurl.com/apidocs/index.html` works? – Roman Marusyk Feb 12 '20 at 18:59
  • why not ? what's the use of launchUrl in published environments then? And https://myapiurl.com/apidocs/index.html works correctly if you enter manually – ameya Feb 13 '20 at 00:24
  • launchUrl is url of your app but not swagger endpoint – Roman Marusyk Feb 13 '20 at 00:28
  • `https://myapiurl.com/apidocs` should redirect to `https://myapiurl.com/apidocs/index.html` but not `https://myapiurl.com` if you don't have controller with redirection – Roman Marusyk Feb 13 '20 at 00:29
  • Yes agreed! but my issue is launchUrl": "apidocs" so I expect https://myapiurl.com to redirect to https://myapiurl.com\apidocs automatically? This is not working for published environments. It works on my local machine ! – ameya Feb 13 '20 at 00:32
  • launchsettings.json only affects local development – Roman Marusyk Feb 13 '20 at 00:43
  • ok... that's why the published environment is not picking up... so that published API should not redirect automatically? I assume this for performance reasons ? – ameya Feb 14 '20 at 20:37

0 Answers0