Merge pull request #5887 from jtkech/patch-2

Fixes #5879: Layout part OnIndexing fails when called in a background task
This commit is contained in:
Piotr Szmyd
2015-10-05 15:36:42 +02:00
2 changed files with 8 additions and 3 deletions

View File

@@ -27,7 +27,8 @@ namespace Orchard.OutputCache.Services {
}
public void Remove(string key) {
_workContext.HttpContext.Cache.Remove(key);
if (_workContext.HttpContext != null)
_workContext.HttpContext.Cache.Remove(key);
}
public void RemoveAll() {
@@ -63,4 +64,4 @@ namespace Orchard.OutputCache.Services {
.Count(x => x.Tenant.Equals(_tenantName, StringComparison.OrdinalIgnoreCase));
}
}
}
}

View File

@@ -27,7 +27,11 @@ namespace Orchard.Environment {
}
public WorkContext GetContext(HttpContextBase httpContext) {
return httpContext.Items[_workContextKey] as WorkContext;
if (!httpContext.IsBackgroundContext())
return httpContext.Items[_workContextKey] as WorkContext;
WorkContext workContext;
return EnsureThreadStaticContexts().TryGetValue(_workContextKey, out workContext) ? workContext : null;
}
public WorkContext GetContext() {