GeekInTheNorth / Stott.Security.Optimizely

A CMS Administration interface for managing security headers for Optimizely CMS Traditional and Hybrid builds.
MIT License
4 stars 1 forks source link

500 Error occurs when overriding Cache Control Header for static files #197

Closed GeekInTheNorth closed 7 months ago

GeekInTheNorth commented 7 months ago

When a website has the following code to override the Cache Control header, then the end point for the JS and CSS files for the admin interface throws a 500 error:

            app.UseResponseCaching();
            app.Use(async (context, next) =>
            {
                if (context.Request is not null)
                {
                    if (context.Response.Headers.ContainsKey(HeaderNames.CacheControl))
                    {
                        context.Response.Headers[HeaderNames.CacheControl] = "no-cache, max-age=0";
                    }
                    else
                    {
                        context.Response.Headers.Add(HeaderNames.CacheControl, "no-cache, max-age=0");
                    }
                }

                await next();
            });