Fixes disposed LifetimeScope issue (#8490)

* fixed scope in in recomputing the context to figure out whether an antiforgery token needs replacing
This commit is contained in:
Matteo Piovanelli
2021-07-30 08:42:13 +02:00
committed by GitHub
parent b37256fc94
commit 074a0b140d

View File

@@ -236,10 +236,11 @@ namespace Orchard.OutputCache.Filters {
Logger.Debug("Response for item '{0}' will not be cached because status code was set to {1} during rendering.", _cacheKey, response.StatusCode); Logger.Debug("Response for item '{0}' will not be cached because status code was set to {1} during rendering.", _cacheKey, response.StatusCode);
return; return;
} }
var cachedOutput = ReplaceRequestVerificationTokenWithBeaconTag(output, response.ContentEncoding);
using (var scope = _workContextAccessor.CreateWorkContextScope()) { using (var scope = _workContextAccessor.CreateWorkContextScope()) {
// ask for the WorkContext again so it refreshes in case the scope has been disposed
_workContext = _workContextAccessor.GetContext(filterContext.HttpContext);
var cachedOutput = ReplaceRequestVerificationTokenWithBeaconTag(output, response.ContentEncoding);
var cacheItem = new CacheItem() { var cacheItem = new CacheItem() {
CachedOnUtc = _now, CachedOnUtc = _now,
Duration = cacheDuration, Duration = cacheDuration,
@@ -648,7 +649,9 @@ namespace Orchard.OutputCache.Filters {
} }
private bool PreventCachingRequestVerificationToken() { private bool PreventCachingRequestVerificationToken() {
return _cacheSettings.CacheAuthenticatedRequests && (!_cacheSettings.VaryByAuthenticationState || _workContext.CurrentUser != null); return _cacheSettings.CacheAuthenticatedRequests
&& (!_cacheSettings.VaryByAuthenticationState
|| _workContext.CurrentUser != null);
} }
protected virtual bool IsIgnoredUrl(string url) { protected virtual bool IsIgnoredUrl(string url) {