Umbraco-CMS: Adding cache control headers stops image cropping from working.

Which exact Umbraco version are you using? For example: 9.0.1 - don’t just write v9

10.0.1

Bug summary

Not sure if I am doing this wrong, but when I in Startup.cs use UseStaticFiles it seems images isn’t cropped or scaled.

app.UseStaticFiles(new StaticFileOptions
{
    OnPrepareResponse = ctx =>
    {
        var headers = ctx.Context.Response.GetTypedHeaders();

        headers.CacheControl = new CacheControlHeaderValue
        {
            Public = true,
            MaxAge = TimeSpan.FromDays(365) // 1 year
        };

        headers.Expires = DateTime.UtcNow.AddYears(1);
    }
});

app.UseRewriter(new RewriteOptions().AddIISUrlRewrite(env.ContentRootFileProvider, "IISUrlRewrite.xml"));

I tried switching the order of UseStaticFiles and UseRewriter, but didn’t seem to make a difference.

Strange thing is that I also have this in a v9.4.1 without issues.

app.UseStaticFiles(new StaticFileOptions
{
    OnPrepareResponse = ctx =>
    {
        var headers = ctx.Context.Response.GetTypedHeaders();

        headers.CacheControl = new CacheControlHeaderValue
        {
            Public = true,
            MaxAge = TimeSpan.FromDays(365) // 1 year
        };

        headers.Expires = DateTime.UtcNow.AddYears(1);
    }
}); 

Specifics

No response

Steps to reproduce

Add app.UseStaticFiles() to Startup.cs before app.UseUmbraco() and notice that images in frontend is no longer cropped/scaled.

You may need to clear browser cache after this change to see the effect.

Expected result / actual result

Images to stay cropped.

Without UseStaticFiles():

image

With UseStaticFiles():

image

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 23 (20 by maintainers)

Most upvoted comments

Thanks @kinless for adding the additional information, do you have a more complete code sample we could see to make it super easy for the docs team to add some information please? 🙏