Wrap HttpContext in an ObjectHandle to avoid cross domain issues

This commit is contained in:
Glenn Condron 2014-05-07 15:11:50 -07:00
parent af38d26fe7
commit 4d78121aa4
1 changed files with 8 additions and 5 deletions

View File

@ -23,7 +23,9 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
#if NET45
using System.Runtime.Remoting;
#endif
namespace Microsoft.AspNet.RequestContainer namespace Microsoft.AspNet.RequestContainer
{ {
public class ContainerMiddleware public class ContainerMiddleware
@ -64,7 +66,8 @@ namespace Microsoft.AspNet.RequestContainer
private HttpContext AccessRootHttpContext() private HttpContext AccessRootHttpContext()
{ {
#if NET45 #if NET45
return CallContext.LogicalGetData(LogicalDataKey) as HttpContext; var handle = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle;
return handle != null ? handle.Unwrap() as HttpContext : null;
#else #else
throw new Exception("TODO: CallContext not available"); throw new Exception("TODO: CallContext not available");
#endif #endif
@ -73,9 +76,9 @@ namespace Microsoft.AspNet.RequestContainer
private HttpContext ExchangeRootHttpContext(HttpContext httpContext) private HttpContext ExchangeRootHttpContext(HttpContext httpContext)
{ {
#if NET45 #if NET45
var prior = CallContext.LogicalGetData(LogicalDataKey) as HttpContext; var prior = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle;
CallContext.LogicalSetData(LogicalDataKey, httpContext); CallContext.LogicalSetData(LogicalDataKey, new ObjectHandle(httpContext));
return prior; return prior != null ? prior.Unwrap() as HttpContext : null;
#else #else
return null; return null;
#endif #endif