mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Update ContextState.cs
This commit is contained in:
parent
9a8a215a98
commit
77024336f9
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user