Merge pull request #6507 from jtkech/patch-15

ContextState: Attempt to fix specflows on teamcity
This commit is contained in:
Sipke Schoorstra
2016-02-29 22:49:13 +01:00
3 changed files with 10 additions and 12 deletions

View File

@@ -30,8 +30,8 @@
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Mvc, Version=5.2.3, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add assembly="Orchard.Framework,Culture=neutral, PublicKeyToken=null" />
<add assembly="Orchard.Core,Culture=neutral, PublicKeyToken=null" />
<add assembly="Orchard.Framework" />
<add assembly="Orchard.Core" />
</assemblies>
</compilation>
</system.web>

View File

@@ -30,8 +30,8 @@
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Mvc, Version=5.2.3, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add assembly="Orchard.Framework,Culture=neutral, PublicKeyToken=null" />
<add assembly="Orchard.Core,Culture=neutral, PublicKeyToken=null" />
<add assembly="Orchard.Framework" />
<add assembly="Orchard.Core" />
</assemblies>
</compilation>
</system.web>

View File

@@ -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;
}
}
}
}