Haminteu
Haminteu

Reputation: 1334

Publish .NET CORE 5.0 API to IIS

I've been struggling for these 2 days.
Does anyone know what's the problem? I tried to publish my .net core API to IIS, but always failed when browse the web.

I did the step to publish same as like this webpage.

After I browse on the server, http://127.0.0.1:5100/swagger/index.html , the page said No webpage was found. I am sure there no system/apps using the 5100 port.

Upvotes: 2

Views: 1690

Answers (1)

Fei Han
Fei Han

Reputation: 27825

After I browse on the server, http://127.0.0.1:5100/swagger/index.html , the page said No webpage was found.

If you check the code of Configure method in Startup.cs, you can find the app will only serve the Swagger UI on Development environment.

if (env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
    app.UseSwagger();
    app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebAppi v1"));
}

If you'd like to serve the Swagger UI on Production environment after you publish it on IIS, you can modify the code as below, then republish it to IIS.

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseSwagger();
    app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebAppi v1"));

    //...

Besides, if your IIS site is just for testing purpose, to quickly resolve the issue and make your site show the Swagger UI as expected, you can try to add an environment variable as below for your site.

enter image description here

Upvotes: 4

Related Questions