From b126dc44950997afa17a4c0bb6ed3903229ed71e Mon Sep 17 00:00:00 2001 From: jtkech Date: Fri, 5 Feb 2016 02:27:37 +0100 Subject: [PATCH] Update ContextState.cs --- src/Orchard/Environment/State/ContextState.cs | 36 ++++++------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/src/Orchard/Environment/State/ContextState.cs b/src/Orchard/Environment/State/ContextState.cs index 8cd1db19c..025adff63 100644 --- a/src/Orchard/Environment/State/ContextState.cs +++ b/src/Orchard/Environment/State/ContextState.cs @@ -1,11 +1,11 @@ -using System; +using System; +using System.Runtime.Remoting; using System.Runtime.Remoting.Messaging; -using System.Web; namespace Orchard.Environment.State { /// - /// Holds some state for the current HttpContext or thread + /// Holds some state through the logical call context /// /// The type of data to store public class ContextState where T : class { @@ -22,35 +22,21 @@ namespace Orchard.Environment.State { } public T GetState() { - if (HttpContext.Current == null) { - var data = CallContext.GetData(_name); + var handle = CallContext.LogicalGetData(_name) as ObjectHandle; + var data = handle != null ? handle.Unwrap() : null; - if (data == null) { - if (_defaultValue != null) { - CallContext.SetData(_name, data = _defaultValue()); - return data as T; - } + if (data == null) { + if (_defaultValue != null) { + CallContext.LogicalSetData(_name, new ObjectHandle(data = _defaultValue())); + return data as T; } - - return data as T; } - if (HttpContext.Current.Items[_name] == null) { - HttpContext.Current.Items[_name] = _defaultValue == null ? null : _defaultValue(); - } - - return HttpContext.Current.Items[_name] as T; - + return data as T; } public void SetState(T state) { - if (HttpContext.Current == null) { - CallContext.SetData(_name, state); - } - else { - HttpContext.Current.Items[_name] = state; - } + CallContext.LogicalSetData(_name, new ObjectHandle(state)); } } } -