diff --git a/src/Orchard.Web/Modules/Orchard.Conditions/Web.config b/src/Orchard.Web/Modules/Orchard.Conditions/Web.config
index 19ca89e37..104465f24 100644
--- a/src/Orchard.Web/Modules/Orchard.Conditions/Web.config
+++ b/src/Orchard.Web/Modules/Orchard.Conditions/Web.config
@@ -30,8 +30,8 @@
-
-
+
+
diff --git a/src/Orchard.Web/Modules/Orchard.Resources/Web.config b/src/Orchard.Web/Modules/Orchard.Resources/Web.config
index 585c0b596..a48e1c34f 100644
--- a/src/Orchard.Web/Modules/Orchard.Resources/Web.config
+++ b/src/Orchard.Web/Modules/Orchard.Resources/Web.config
@@ -30,8 +30,8 @@
-
-
+
+
diff --git a/src/Orchard/Environment/State/ContextState.cs b/src/Orchard/Environment/State/ContextState.cs
index f41887c6b..4b8f6129d 100644
--- a/src/Orchard/Environment/State/ContextState.cs
+++ b/src/Orchard/Environment/State/ContextState.cs
@@ -1,4 +1,5 @@
using System;
+using System.Runtime.Remoting;
using System.Runtime.Remoting.Messaging;
using System.Web;
using Orchard.Mvc.Extensions;
@@ -23,11 +24,15 @@ namespace Orchard.Environment.State {
public T GetState() {
if (HttpContext.Current.IsBackgroundHttpContext()) {
+ // Because CallContext Logical Data can be shared across application domains,
+ // here we also check if it's a real local instance, not a tranparent proxy.
var handle = CallContext.LogicalGetData(_name) as ObjectHandle;
- var data = handle != null ? handle.Unwrap() : null;
+ var data = handle != null && !RemotingServices.IsTransparentProxy(handle) ? handle.Unwrap() : null;
if (data == null) {
if (_defaultValue != null) {
+ // Because CallContext Logical Data can be shared across application domains,
+ // data are wrapped in an ObjectHandle that inherits from MarshalByRefObject.
CallContext.LogicalSetData(_name, new ObjectHandle(data = _defaultValue()));
return data as T;
}
@@ -51,12 +56,5 @@ namespace Orchard.Environment.State {
HttpContext.Current.Items[_name] = state;
}
}
-
- internal class ObjectHandle : System.Runtime.Remoting.ObjectHandle {
- public ObjectHandle(object o) : base(o) { }
- public override object InitializeLifetimeService() {
- return null;
- }
- }
}
}