简体   繁体   中英

Swagger UI show 404 error when I deploy it on IIS

I have an asp.net core application with vue.js. I made web api. And when I'm debugging via localhost - everything is fine. Swagger UI is working, also as application. But when I deploy app to the IIS, Swagger don't work and show 404 error.

Here is swagger configuration in Startup.cs

services.AddSwaggerGen(config =>
        {
            var xmlFile = $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}.xml";
            var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
            config.IncludeXmlComments(xmlPath);
        });
app.UseSwagger(options =>
            {
                options.SerializeAsV2 = true;
                options.RouteTemplate = "info/swagger/{documentname}/swagger.json";
            });

            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/info/swagger/v1/swagger.json", "v1");
                options.RoutePrefix = "info/swagger";
            });

What should I do? changing SwaggerEnpoint to "../info/swager....." don't help. I need to working asp .net core app and also swagger on IIS.

You can use the below endpoint to enable swagger on IIS:

 app.UseSwaggerUI(options  =>
 {
   options.SwaggerEndpoint("./swagger/v1/swagger.json", "v1");
   options.RoutePrefix = string.Empty;
});

The problem was in

app.UseSwagger(options =>
            {
                options.SerializeAsV2 = true;
            });

app.UseSwaggerUI(options =>
        {
            options.SwaggerEndpoint("/applicationName/swagger/v1/swagger.json", "v1");
            options.RoutePrefix = "info/swagger";
        });

removing options.RouteTemplate and replace "info" on "appName" in options.SwaggerEndpoint helps me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM