mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Update HttpContextAccessor.cs
This commit is contained in:
@@ -1,13 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Runtime.Remoting;
|
|
||||||
using System.Runtime.Remoting.Messaging;
|
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
using Autofac;
|
||||||
|
|
||||||
namespace Orchard.Mvc {
|
namespace Orchard.Mvc {
|
||||||
|
|
||||||
public class HttpContextAccessor : IHttpContextAccessor {
|
public class HttpContextAccessor : IHttpContextAccessor {
|
||||||
|
readonly ILifetimeScope _lifetimeScope;
|
||||||
private HttpContextBase _httpContext;
|
private HttpContextBase _httpContext;
|
||||||
|
|
||||||
|
public HttpContextAccessor(ILifetimeScope lifetimeScope) {
|
||||||
|
_lifetimeScope = lifetimeScope;
|
||||||
|
}
|
||||||
|
|
||||||
public HttpContextBase Current() {
|
public HttpContextBase Current() {
|
||||||
var httpContext = GetStaticProperty();
|
var httpContext = GetStaticProperty();
|
||||||
|
|
||||||
@@ -17,8 +20,10 @@ namespace Orchard.Mvc {
|
|||||||
if (_httpContext != null)
|
if (_httpContext != null)
|
||||||
return _httpContext;
|
return _httpContext;
|
||||||
|
|
||||||
var context = CallContext.LogicalGetData("HttpContext") as ObjectHandle;
|
var workContext = _lifetimeScope.IsRegistered<IWorkContextAccessor>() ?
|
||||||
return context != null ? context.Unwrap() as HttpContextBase : null;
|
_lifetimeScope.Resolve<IWorkContextAccessor>().GetContext(null) : null;
|
||||||
|
|
||||||
|
return workContext != null ? workContext.HttpContext : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Set(HttpContextBase httpContext) {
|
public void Set(HttpContextBase httpContext) {
|
||||||
|
Reference in New Issue
Block a user