What is the "right" way to serve new static file extensions?

I knew what I was doing had to be over the top!

I’m having a little trouble running the example as-is. With the following change, I was able to serve *.riv files again.

using Microsoft.AspNetCore.StaticFiles;
using Umbraco.Cms.Core.Composing;

public class RiveStaticFileComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        builder.Services.Configure<StaticFileOptions>(options =>
        {
            var provider = options.ContentTypeProvider as FileExtensionContentTypeProvider
                           ?? new FileExtensionContentTypeProvider();
            provider.Mappings[".riv"] = "application/octet-stream";
            options.ContentTypeProvider = provider;
        });
    }
}

(Hopefully I haven’t misunderstood what’s happening under the hood here…)

Thank you @sebastiaan!

1 Like