mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Cherry picked 9bf6ac5718
.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Core.Settings.Models;
|
using Orchard.Core.Settings.Models;
|
||||||
using Orchard.Mvc;
|
using Orchard.Mvc;
|
||||||
|
using Orchard.Mvc.Extensions;
|
||||||
using Orchard.Settings;
|
using Orchard.Settings;
|
||||||
using Orchard.Utility.Extensions;
|
using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ namespace Orchard.Core.Settings.Commands {
|
|||||||
|
|
||||||
// Retrieve request URL if BaseUrl not provided as a switch value
|
// Retrieve request URL if BaseUrl not provided as a switch value
|
||||||
if (string.IsNullOrEmpty(BaseUrl)) {
|
if (string.IsNullOrEmpty(BaseUrl)) {
|
||||||
if (_httpContextAccessor.Current() == null) {
|
if (_httpContextAccessor.Current().IsBackgroundContext()) {
|
||||||
Context.Output.WriteLine(T("No HTTP request available to determine the base url of the site"));
|
Context.Output.WriteLine(T("No HTTP request available to determine the base url of the site"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,7 @@ using Orchard.DisplayManagement.Shapes;
|
|||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.Mvc;
|
using Orchard.Mvc;
|
||||||
|
using Orchard.Mvc.Extensions;
|
||||||
|
|
||||||
namespace Orchard.DisplayManagement.Implementation {
|
namespace Orchard.DisplayManagement.Implementation {
|
||||||
public class DefaultDisplayManager : IDisplayManager {
|
public class DefaultDisplayManager : IDisplayManager {
|
||||||
@@ -61,7 +62,7 @@ namespace Orchard.DisplayManagement.Implementation {
|
|||||||
return CoerceHtmlString(context.Value);
|
return CoerceHtmlString(context.Value);
|
||||||
|
|
||||||
var workContext = _workContextAccessor.GetContext();
|
var workContext = _workContextAccessor.GetContext();
|
||||||
var shapeTable = _httpContextAccessor.Current() != null
|
var shapeTable = !_httpContextAccessor.Current().IsBackgroundContext()
|
||||||
? _shapeTableLocator.Value.Lookup(workContext.CurrentTheme.Id)
|
? _shapeTableLocator.Value.Lookup(workContext.CurrentTheme.Id)
|
||||||
: _shapeTableLocator.Value.Lookup(null);
|
: _shapeTableLocator.Value.Lookup(null);
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@ using System.Web;
|
|||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.Mvc;
|
using Orchard.Mvc;
|
||||||
|
using Orchard.Mvc.Extensions;
|
||||||
using Orchard.Services;
|
using Orchard.Services;
|
||||||
using Orchard.Utility.Extensions;
|
using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ namespace Orchard.Environment {
|
|||||||
// current request can be processed correctly. So, we redirect to the same URL, so that the
|
// current request can be processed correctly. So, we redirect to the same URL, so that the
|
||||||
// new request will come to the newly started AppDomain.
|
// new request will come to the newly started AppDomain.
|
||||||
var httpContext = _httpContextAccessor.Current();
|
var httpContext = _httpContextAccessor.Current();
|
||||||
if (httpContext != null) {
|
if (!httpContext.IsBackgroundContext()) {
|
||||||
// Don't redirect posts...
|
// Don't redirect posts...
|
||||||
if (httpContext.Request.RequestType == "GET") {
|
if (httpContext.Request.RequestType == "GET") {
|
||||||
httpContext.Response.Redirect(HttpContext.Current.Request.ToUrlString(), true /*endResponse*/);
|
httpContext.Response.Redirect(HttpContext.Current.Request.ToUrlString(), true /*endResponse*/);
|
||||||
|
@@ -63,7 +63,7 @@ namespace Orchard.Environment {
|
|||||||
builder.RegisterType<AppDomainAssemblyNameResolver>().As<IAssemblyNameResolver>().SingleInstance();
|
builder.RegisterType<AppDomainAssemblyNameResolver>().As<IAssemblyNameResolver>().SingleInstance();
|
||||||
builder.RegisterType<GacAssemblyNameResolver>().As<IAssemblyNameResolver>().SingleInstance();
|
builder.RegisterType<GacAssemblyNameResolver>().As<IAssemblyNameResolver>().SingleInstance();
|
||||||
builder.RegisterType<OrchardFrameworkAssemblyNameResolver>().As<IAssemblyNameResolver>().SingleInstance();
|
builder.RegisterType<OrchardFrameworkAssemblyNameResolver>().As<IAssemblyNameResolver>().SingleInstance();
|
||||||
builder.RegisterType<HttpContextAccessor>().As<IHttpContextAccessor>().SingleInstance();
|
builder.RegisterType<HttpContextAccessor>().As<IHttpContextAccessor>().InstancePerDependency();
|
||||||
builder.RegisterType<ViewsBackgroundCompilation>().As<IViewsBackgroundCompilation>().SingleInstance();
|
builder.RegisterType<ViewsBackgroundCompilation>().As<IViewsBackgroundCompilation>().SingleInstance();
|
||||||
builder.RegisterType<DefaultExceptionPolicy>().As<IExceptionPolicy>().SingleInstance();
|
builder.RegisterType<DefaultExceptionPolicy>().As<IExceptionPolicy>().SingleInstance();
|
||||||
builder.RegisterType<DefaultCriticalErrorProvider>().As<ICriticalErrorProvider>().SingleInstance();
|
builder.RegisterType<DefaultCriticalErrorProvider>().As<ICriticalErrorProvider>().SingleInstance();
|
||||||
|
@@ -5,6 +5,7 @@ using System.Web;
|
|||||||
using Autofac;
|
using Autofac;
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.Mvc;
|
using Orchard.Mvc;
|
||||||
|
using Orchard.Mvc.Extensions;
|
||||||
|
|
||||||
namespace Orchard.Environment {
|
namespace Orchard.Environment {
|
||||||
public class WorkContextAccessor : IWorkContextAccessor {
|
public class WorkContextAccessor : IWorkContextAccessor {
|
||||||
@@ -31,7 +32,7 @@ namespace Orchard.Environment {
|
|||||||
|
|
||||||
public WorkContext GetContext() {
|
public WorkContext GetContext() {
|
||||||
var httpContext = _httpContextAccessor.Current();
|
var httpContext = _httpContextAccessor.Current();
|
||||||
if (httpContext != null)
|
if (!httpContext.IsBackgroundContext())
|
||||||
return GetContext(httpContext);
|
return GetContext(httpContext);
|
||||||
|
|
||||||
WorkContext workContext;
|
WorkContext workContext;
|
||||||
@@ -55,7 +56,7 @@ namespace Orchard.Environment {
|
|||||||
|
|
||||||
public IWorkContextScope CreateWorkContextScope() {
|
public IWorkContextScope CreateWorkContextScope() {
|
||||||
var httpContext = _httpContextAccessor.Current();
|
var httpContext = _httpContextAccessor.Current();
|
||||||
if (httpContext != null)
|
if (!httpContext.IsBackgroundContext())
|
||||||
return CreateWorkContextScope(httpContext);
|
return CreateWorkContextScope(httpContext);
|
||||||
|
|
||||||
var workLifetime = _lifetimeScope.BeginLifetimeScope("work");
|
var workLifetime = _lifetimeScope.BeginLifetimeScope("work");
|
||||||
|
9
src/Orchard/Mvc/Extensions/HttpContextBaseExtensions.cs
Normal file
9
src/Orchard/Mvc/Extensions/HttpContextBaseExtensions.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using System.Web;
|
||||||
|
|
||||||
|
namespace Orchard.Mvc.Extensions {
|
||||||
|
public static class HttpContextBaseExtensions {
|
||||||
|
public static bool IsBackgroundContext(this HttpContextBase httpContextBase) {
|
||||||
|
return httpContextBase == null || httpContextBase is MvcModule.HttpContextPlaceholder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
|
||||||
namespace Orchard.Mvc {
|
namespace Orchard.Mvc {
|
||||||
|
@@ -85,7 +85,7 @@ namespace Orchard.Mvc {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Standin context for background tasks.
|
/// Standin context for background tasks.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class HttpContextPlaceholder : HttpContextBase {
|
public class HttpContextPlaceholder : HttpContextBase {
|
||||||
private readonly Lazy<string> _baseUrl;
|
private readonly Lazy<string> _baseUrl;
|
||||||
private readonly IDictionary _items = new Dictionary<object, object>();
|
private readonly IDictionary _items = new Dictionary<object, object>();
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ namespace Orchard.Mvc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class HttpResponsePlaceholder : HttpResponseBase {
|
public class HttpResponsePlaceholder : HttpResponseBase {
|
||||||
public override string ApplyAppPathModifier(string virtualPath) {
|
public override string ApplyAppPathModifier(string virtualPath) {
|
||||||
return virtualPath;
|
return virtualPath;
|
||||||
}
|
}
|
||||||
@@ -135,7 +135,7 @@ namespace Orchard.Mvc {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// standin context for background tasks.
|
/// standin context for background tasks.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class HttpRequestPlaceholder : HttpRequestBase {
|
public class HttpRequestPlaceholder : HttpRequestBase {
|
||||||
private readonly Uri _uri;
|
private readonly Uri _uri;
|
||||||
|
|
||||||
public HttpRequestPlaceholder(Uri uri) {
|
public HttpRequestPlaceholder(Uri uri) {
|
||||||
@@ -217,7 +217,7 @@ namespace Orchard.Mvc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class HttpBrowserCapabilitiesPlaceholder : HttpBrowserCapabilitiesBase {
|
public class HttpBrowserCapabilitiesPlaceholder : HttpBrowserCapabilitiesBase {
|
||||||
public override string this[string key] {
|
public override string this[string key] {
|
||||||
get {
|
get {
|
||||||
return "";
|
return "";
|
||||||
|
@@ -317,6 +317,7 @@
|
|||||||
<Compile Include="Mvc\DataAnnotations\LocalizedModelValidatorProvider.cs" />
|
<Compile Include="Mvc\DataAnnotations\LocalizedModelValidatorProvider.cs" />
|
||||||
<Compile Include="Mvc\DataAnnotations\LocalizedRequiredAttribute.cs" />
|
<Compile Include="Mvc\DataAnnotations\LocalizedRequiredAttribute.cs" />
|
||||||
<Compile Include="Mvc\Extensions\RouteExtension.cs" />
|
<Compile Include="Mvc\Extensions\RouteExtension.cs" />
|
||||||
|
<Compile Include="Mvc\Extensions\HttpContextBaseExtensions.cs" />
|
||||||
<Compile Include="Mvc\FormValueRequiredAttribute.cs" />
|
<Compile Include="Mvc\FormValueRequiredAttribute.cs" />
|
||||||
<Compile Include="Mvc\HttpContextAccessor.cs" />
|
<Compile Include="Mvc\HttpContextAccessor.cs" />
|
||||||
<Compile Include="Mvc\HttpContextWorkContext.cs" />
|
<Compile Include="Mvc\HttpContextWorkContext.cs" />
|
||||||
|
@@ -5,6 +5,7 @@ using Orchard.Environment.Configuration;
|
|||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Mvc;
|
using Orchard.Mvc;
|
||||||
|
using Orchard.Mvc.Extensions;
|
||||||
using Orchard.Services;
|
using Orchard.Services;
|
||||||
|
|
||||||
namespace Orchard.Security.Providers {
|
namespace Orchard.Security.Providers {
|
||||||
@@ -102,7 +103,7 @@ namespace Orchard.Security.Providers {
|
|||||||
return _signedInUser;
|
return _signedInUser;
|
||||||
|
|
||||||
var httpContext = _httpContextAccessor.Current();
|
var httpContext = _httpContextAccessor.Current();
|
||||||
if (httpContext == null || !httpContext.Request.IsAuthenticated || !(httpContext.User.Identity is FormsIdentity)) {
|
if (httpContext.IsBackgroundContext() || !httpContext.Request.IsAuthenticated || !(httpContext.User.Identity is FormsIdentity)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user