GeekInTheNorth/Stott.Optimizely.RobotsHandler

500 Error occurs when overriding Cache Control Header for static files

GeekInTheNorth opened this issue · 0 comments

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();
            });