From 35c379191e3fa20cc00aa107786b9422bc8dd561 Mon Sep 17 00:00:00 2001 From: Carl Woodhouse Date: Thu, 21 Jul 2016 20:17:33 +0100 Subject: [PATCH] [Fixes #7034] Don't cache pages when status code is changed in the view * Fixed the output caching of non 200 responses when errors are thrown in views * Added debug message to output cache when the response isn't cached due to a non 200 status code. --- .../Orchard.OutputCache/Filters/OutputCacheFilter.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs b/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs index 9ada76e2b..595f896ed 100644 --- a/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs +++ b/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs @@ -226,6 +226,12 @@ namespace Orchard.OutputCache.Filters { // To prevent access to the original lifetime scope a new work context scope should be created here and dependencies // should be resolved from it. + // Recheck the response status code incase it was modified before the callback. + if (response.StatusCode != 200) { + Logger.Debug("Response for item '{0}' will not be cached because status code was set to {1} during rendering.", _cacheKey, response.StatusCode); + return; + } + using (var scope = _workContextAccessor.CreateWorkContextScope()) { var cacheItem = new CacheItem() { CachedOnUtc = _now,