Skip to content

Adding cache control headers stops image cropping from working. #12666

Closed
@bjarnef

Description

@bjarnef

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions