Swagger UI not showed once pubblished in IIS

Hi guys,
I’m facing a problem. I add the OpenApiFeature to my apphost (ServiceStack.* version 6.0.2) in this way

Plugins.Add(new OpenApiFeature());

If I execute the apphost locally everything works as a charm, but once I pubblish it on production (IIS 10) I didn’t see the “real page” but just this

looking at the loading process of the page I found all these errors:

It looks like swagger ui component are not published as well. What am I doing wrong?
Best regards

The swagger files are embedded resources inside the ServiceStack.Api.OpenApi.dll as such, it will always be “published”.

If it’s returning a 404, I’m assuming either interfering with the pre-configured VirtualFileSources or something is short-circuiting the request.

Find out what’s returning the 404, i.e. whether it’s from IIS or ServiceStack which you should be able to tell from the Powered-By HTTP Response Header.

This is the response

and this is the publish output folder

From my understanding is something on my iis, but what?

Looks like something is handling the Request before it can reach ServiceStack.

Try moving your app.UseServiceStack(new AppHost()) middleware higher in the pipeline. Do you have any /swagger-ui folders, if so try renaming it to see if that’s the cause of the conflict.

I never call that method

my application is an asp.net page where on the start method I create a new AppHost in this way

My AppHost is declared in this way

Is it right?

Ok so this is a .NET Framework App, in that case I’m not sure why it’s returning a 404, are you running any custom IIS handlers that could interfere with it, or have a local /swagger-ui/ folder?

Yes, it is a .NET Framework app. In the same PC there is another apphost (self hosted) with SwaggerUI enabled (and it works), the one with the problem is hosted within an IIS 10 istance where there is no customer handlers nor swagger-ui folder.

Then can’t tell from here, if you can put together a small stand-alone repro on GitHub I can check it out.

I did a new project starting from scratch and once published on my iis 10 it show 404 error as well.
I created a repo on github and shared with you.


This template doesn’t run at all, can you send a link to a new project that’s updated to use the latest ServiceStack v8.2.2 Version running at least .NET Framework v4.7.2.

Note, you don’t need to check in any /bin or /obj folders with your projects as they’ll be restored by VS when building the project.

BTW I’ve tried running Open API in IIS without issue.

  1. Download Web template from Create new .NET Framework project - ServiceStack

  2. Install latest ServiceStack.Api.OpenApi NuGet Package

  3. Register Plugin in AppHost:

public override void Configure(Container container)
    Plugins.Add(new ServiceStack.Api.OpenApi.OpenApiFeature());
  1. Create Virtual IIS Directory in MyApp > Properties > Web

  2. Run

I just download the template (that use last version of ServiceStack), add the reference to OpenAPI and it works as a charm on my local IIS Express. Same project published on my IIS 10 environment doesn’t work.

How is suppose to be setup the website in IIS in order to discover the embedded resources? I created the virtual directory “swagger-ui” on IIS but still resources are not discovered.

Remove any /swagger-ui folders or handlers in your project or IIS, IIS shouldn’t have anything named /swagger-ui that conflicts with it, as long as the /swagger-ui/* requests reach ServiceStack, it should handle it.

The issue sounds like IIS or ASP .NET is handling the request and returning a 404 before the request can reach ServiceStack, I can’t tell what that is from here.

Alternatively if you can’t figure it out, you can try copying the entire /swagger-ui folder in your /wwwroot, which your IIS or ASP.NET can serve directly instead.

Easiest way to do that would be to download the a zip of the GitHub Repo ServiceStack.zip, extracting it and copying the /ServiceStack/src/ServiceStack.Api.OpenApi/swagger-ui folder to your /wwwroot.

1 Like

I agree with you

Easiest way to do that would be to download the a zip of the GitHub Repo ServiceStack.zip, extracting it and copying the /ServiceStack/src/ServiceStack.Api.OpenApi/swagger-ui folder to your /wwwroot .

Once I put the swagger-ui folder on my site root It start to works as expected. It is not be best solution, but it works, so I will keep it.


1 Like