mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 03:25:23 +08:00
Update HttpContextAccessor.cs
This commit is contained in:
@@ -6,6 +6,7 @@ namespace Orchard.Mvc {
|
|||||||
public class HttpContextAccessor : IHttpContextAccessor {
|
public class HttpContextAccessor : IHttpContextAccessor {
|
||||||
readonly ILifetimeScope _lifetimeScope;
|
readonly ILifetimeScope _lifetimeScope;
|
||||||
private HttpContextBase _httpContext;
|
private HttpContextBase _httpContext;
|
||||||
|
private IWorkContextAccessor _wca;
|
||||||
|
|
||||||
public HttpContextAccessor(ILifetimeScope lifetimeScope) {
|
public HttpContextAccessor(ILifetimeScope lifetimeScope) {
|
||||||
_lifetimeScope = lifetimeScope;
|
_lifetimeScope = lifetimeScope;
|
||||||
@@ -20,9 +21,10 @@ namespace Orchard.Mvc {
|
|||||||
if (_httpContext != null)
|
if (_httpContext != null)
|
||||||
return _httpContext;
|
return _httpContext;
|
||||||
|
|
||||||
var workContext = _lifetimeScope.IsRegistered<IWorkContextAccessor>() ?
|
if (_wca == null && _lifetimeScope.IsRegistered<IWorkContextAccessor>())
|
||||||
_lifetimeScope.Resolve<IWorkContextAccessor>().GetContext(null) : null;
|
_wca = _lifetimeScope.Resolve<IWorkContextAccessor>();
|
||||||
|
|
||||||
|
var workContext = _wca != null ? _wca.GetContext(null) : null;
|
||||||
return workContext != null ? workContext.HttpContext : null;
|
return workContext != null ? workContext.HttpContext : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user