From 7cdb984f4fd0cb8cdfcc59d0b4c1394e9fb346dd Mon Sep 17 00:00:00 2001 From: Xeevis Date: Wed, 13 May 2015 15:24:46 +0200 Subject: [PATCH 01/13] #5224: Fix for missing charset in response header for cached output --- .../Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs b/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs index f93e4c855..a92736ae1 100644 --- a/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs +++ b/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs @@ -447,6 +447,9 @@ namespace Orchard.OutputCache.Filters { private void ServeCachedItem(ActionExecutingContext filterContext, CacheItem cacheItem) { var response = filterContext.HttpContext.Response; + // Fix for missing charset in response headers + response.Charset = response.Charset; + // Adds some caching information to the output if requested. if (CacheSettings.DebugMode) { response.AddHeader("X-Cached-On", cacheItem.CachedOnUtc.ToString("r")); From 2339bdc9663cdc27efb17ae5b020f9c29ebaf985 Mon Sep 17 00:00:00 2001 From: mvarblow Date: Wed, 13 May 2015 16:45:55 -0400 Subject: [PATCH 02/13] Update SslSettingsPartDriver.cs Fixed issue 5274 --- .../Drivers/SslSettingsPartDriver.cs | 21 ++----------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.SecureSocketsLayer/Drivers/SslSettingsPartDriver.cs b/src/Orchard.Web/Modules/Orchard.SecureSocketsLayer/Drivers/SslSettingsPartDriver.cs index fa259a1cf..89dd0cd63 100644 --- a/src/Orchard.Web/Modules/Orchard.SecureSocketsLayer/Drivers/SslSettingsPartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.SecureSocketsLayer/Drivers/SslSettingsPartDriver.cs @@ -36,25 +36,8 @@ namespace Orchard.SecureSocketsLayer.Drivers { } protected override void Importing(SslSettingsPart part, ImportContentContext context) { - var elementName = part.PartDefinition.Name; - part.Enabled = bool.Parse(context.Attribute(elementName, "Enabled") ?? "false"); - part.SecureEverything = bool.Parse(context.Attribute(elementName, "SecureEverything") ?? "true"); - part.CustomEnabled = bool.Parse(context.Attribute(elementName, "CustomEnabled") ?? "false"); - part.Urls = context.Attribute(elementName, "Urls") ?? ""; - part.InsecureHostName = context.Attribute(elementName, "InsecureHostName") ?? ""; - part.SecureHostName = context.Attribute(elementName, "SecureHostName") ?? ""; - + base.Importing(part, context); _signals.Trigger(SslSettingsPart.CacheKey); } - - protected override void Exporting(SslSettingsPart part, ExportContentContext context) { - var el = context.Element(part.PartDefinition.Name); - el.SetAttributeValue("Enabled", part.Enabled); - el.SetAttributeValue("SecureEverything", part.SecureEverything); - el.SetAttributeValue("CustomEnabled", part.CustomEnabled); - el.SetAttributeValue("Urls", part.Urls); - el.SetAttributeValue("InsecureHostName", part.InsecureHostName); - el.SetAttributeValue("SecureHostName", part.SecureHostName); - } } -} \ No newline at end of file +} From f5862bd62885f154c2b9c0d06379a0cf25071b86 Mon Sep 17 00:00:00 2001 From: mvarblow Date: Wed, 13 May 2015 16:54:23 -0400 Subject: [PATCH 03/13] Update MediaController.cs Fix for issue https://github.com/OrchardCMS/Orchard/issues/5275. The fix is to return the FolderPath element in the response to the media search request so that the folderPath check in the javascript code succeeds. --- .../Modules/Orchard.Search/Controllers/MediaController.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Search/Controllers/MediaController.cs b/src/Orchard.Web/Modules/Orchard.Search/Controllers/MediaController.cs index e7e029c19..0acb1c2ed 100644 --- a/src/Orchard.Web/Modules/Orchard.Search/Controllers/MediaController.cs +++ b/src/Orchard.Web/Modules/Orchard.Search/Controllers/MediaController.cs @@ -59,10 +59,11 @@ namespace Orchard.Search.Controllers { var viewModel = new MediaManagerMediaItemsViewModel { MediaItems = mediaItems, - MediaItemsCount = mediaPartsCount + MediaItemsCount = mediaPartsCount, + FolderPath = folderPath }; return View(viewModel); } } -} \ No newline at end of file +} From fa7bf025b973b1296f7806494caefa97ee8fd18d Mon Sep 17 00:00:00 2001 From: mvarblow Date: Wed, 13 May 2015 16:57:10 -0400 Subject: [PATCH 04/13] Update MediaItems.cshtml --- .../Modules/Orchard.Search/Views/Media/MediaItems.cshtml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Search/Views/Media/MediaItems.cshtml b/src/Orchard.Web/Modules/Orchard.Search/Views/Media/MediaItems.cshtml index 5263d9707..3dad0b9ef 100644 --- a/src/Orchard.Web/Modules/Orchard.Search/Views/Media/MediaItems.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Search/Views/Media/MediaItems.cshtml @@ -17,8 +17,9 @@ mimeTypeClass = x.MediaPart.MimeType.HtmlClassify(), thumbnail = Display(x.Shape).ToString(), editLink = Url.ItemEditUrl(x.MediaPart) - }).ToArray() + }).ToArray(), + folderPath = Model.FolderPath })) } - \ No newline at end of file + From 4d242e83df4f61e0f20adea963cbfadd35efc120 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 21 May 2015 17:24:45 +0200 Subject: [PATCH 05/13] #5306: Injecting HttpContextBase directly. This will ensure that an actual HttpContext object will be available in case of background task operations thanks to the way HttpContextBase is registered (providing a placeholder object in case of background operations). --- .../Services/CurrentControllerAccessor.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Layouts/Services/CurrentControllerAccessor.cs b/src/Orchard.Web/Modules/Orchard.Layouts/Services/CurrentControllerAccessor.cs index 9ae1abeaa..5cd9eeb0a 100644 --- a/src/Orchard.Web/Modules/Orchard.Layouts/Services/CurrentControllerAccessor.cs +++ b/src/Orchard.Web/Modules/Orchard.Layouts/Services/CurrentControllerAccessor.cs @@ -1,16 +1,19 @@ +using System.Web; using System.Web.Mvc; using Orchard.Layouts.Filters; -using Orchard.Mvc; namespace Orchard.Layouts.Services { public class CurrentControllerAccessor : ICurrentControllerAccessor { - private readonly IHttpContextAccessor _httpContextAccessor; - public CurrentControllerAccessor(IHttpContextAccessor httpContextAccessor) { - _httpContextAccessor = httpContextAccessor; + private readonly IWorkContextAccessor _wca; + private readonly HttpContextBase _httpContext; + + public CurrentControllerAccessor(IWorkContextAccessor wca, HttpContextBase httpContext) { + _wca = wca; + _httpContext = httpContext; } public Controller CurrentController { - get { return (Controller) _httpContextAccessor.Current().Items[ControllerAccessorFilter.CurrentControllerKey]; } + get { return (Controller) _httpContext.Items[ControllerAccessorFilter.CurrentControllerKey]; } } } } \ No newline at end of file From ce36e115d0d42397abd45ec7c587a99734972823 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 21 May 2015 17:25:50 +0200 Subject: [PATCH 06/13] Removed unnecessary field. --- .../Orchard.Layouts/Services/CurrentControllerAccessor.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Layouts/Services/CurrentControllerAccessor.cs b/src/Orchard.Web/Modules/Orchard.Layouts/Services/CurrentControllerAccessor.cs index 5cd9eeb0a..546a3f8df 100644 --- a/src/Orchard.Web/Modules/Orchard.Layouts/Services/CurrentControllerAccessor.cs +++ b/src/Orchard.Web/Modules/Orchard.Layouts/Services/CurrentControllerAccessor.cs @@ -4,11 +4,9 @@ using Orchard.Layouts.Filters; namespace Orchard.Layouts.Services { public class CurrentControllerAccessor : ICurrentControllerAccessor { - private readonly IWorkContextAccessor _wca; private readonly HttpContextBase _httpContext; - public CurrentControllerAccessor(IWorkContextAccessor wca, HttpContextBase httpContext) { - _wca = wca; + public CurrentControllerAccessor(HttpContextBase httpContext) { _httpContext = httpContext; } From 6eb9e0d457c303c407a07e5c94c3566386715555 Mon Sep 17 00:00:00 2001 From: Skrypt Date: Thu, 21 May 2015 16:10:09 -0400 Subject: [PATCH 07/13] Fixing #5281 --- src/Orchard.Web/Core/Navigation/Views/Admin/Index.cshtml | 2 +- .../Views/EditorTemplates/Parts.MenuWidget.Edit.cshtml | 2 +- .../EditorTemplates/Parts.Navigation.Menu.Edit.cshtml | 2 +- .../Views/EditorTemplates/Parts.Navigation.Edit.cshtml | 2 +- src/Orchard/Mvc/Html/ContentItemExtensions.cs | 8 ++++++-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Orchard.Web/Core/Navigation/Views/Admin/Index.cshtml b/src/Orchard.Web/Core/Navigation/Views/Admin/Index.cshtml index bb81da637..8a2c7a776 100644 --- a/src/Orchard.Web/Core/Navigation/Views/Admin/Index.cshtml +++ b/src/Orchard.Web/Core/Navigation/Views/Admin/Index.cshtml @@ -22,7 +22,7 @@ @if (hasPermission) { diff --git a/src/Orchard.Web/Core/Navigation/Views/EditorTemplates/Parts.MenuWidget.Edit.cshtml b/src/Orchard.Web/Core/Navigation/Views/EditorTemplates/Parts.MenuWidget.Edit.cshtml index c505a208b..cb568e8ff 100644 --- a/src/Orchard.Web/Core/Navigation/Views/EditorTemplates/Parts.MenuWidget.Edit.cshtml +++ b/src/Orchard.Web/Core/Navigation/Views/EditorTemplates/Parts.MenuWidget.Edit.cshtml @@ -6,7 +6,7 @@ @Html.LabelFor(m => m.CurrentMenuId, T("For Menu")) @T("Select which menu you want to display") diff --git a/src/Orchard.Web/Core/Navigation/Views/EditorTemplates/Parts.Navigation.Menu.Edit.cshtml b/src/Orchard.Web/Core/Navigation/Views/EditorTemplates/Parts.Navigation.Menu.Edit.cshtml index c81dd1ede..a51394ccc 100644 --- a/src/Orchard.Web/Core/Navigation/Views/EditorTemplates/Parts.Navigation.Menu.Edit.cshtml +++ b/src/Orchard.Web/Core/Navigation/Views/EditorTemplates/Parts.Navigation.Menu.Edit.cshtml @@ -11,7 +11,7 @@
@T("Select which menu you want the content item to be displayed on.") diff --git a/src/Orchard.Web/Modules/Orchard.ContentPicker/Views/EditorTemplates/Parts.Navigation.Edit.cshtml b/src/Orchard.Web/Modules/Orchard.ContentPicker/Views/EditorTemplates/Parts.Navigation.Edit.cshtml index 8234426e4..972007790 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentPicker/Views/EditorTemplates/Parts.Navigation.Edit.cshtml +++ b/src/Orchard.Web/Modules/Orchard.ContentPicker/Views/EditorTemplates/Parts.Navigation.Edit.cshtml @@ -29,7 +29,7 @@
@T("Select which menu you want the content item to be added on.") diff --git a/src/Orchard/Mvc/Html/ContentItemExtensions.cs b/src/Orchard/Mvc/Html/ContentItemExtensions.cs index 4f30ea2a9..a6fc28281 100644 --- a/src/Orchard/Mvc/Html/ContentItemExtensions.cs +++ b/src/Orchard/Mvc/Html/ContentItemExtensions.cs @@ -7,11 +7,15 @@ using Orchard.Utility.Extensions; namespace Orchard.Mvc.Html { public static class ContentItemExtensions { - public static MvcHtmlString ItemDisplayText(this HtmlHelper html, IContent content) { + public static MvcHtmlString ItemDisplayText(this HtmlHelper html, IContent content, bool encode = true) { var metadata = content.ContentItem.ContentManager.GetItemMetadata(content); if (metadata.DisplayText == null) return null; - return MvcHtmlString.Create(html.Encode(metadata.DisplayText)); + if (encode) { + return MvcHtmlString.Create(html.Encode(metadata.DisplayText)); + } else { + return MvcHtmlString.Create(metadata.DisplayText); + } } public static MvcHtmlString ItemDisplayLink(this HtmlHelper html, IContent content) { From 754114c8e6edae63ce69886e9d5a3df4571cadbb Mon Sep 17 00:00:00 2001 From: Skrypt Date: Thu, 21 May 2015 16:23:27 -0400 Subject: [PATCH 08/13] Rebase on 1.9.x since this is a bug fix Fixing #4963 --- .../Navigation/Scripts/navigation-admin.js | 2 +- .../Core/Navigation/Views/Admin/Index.cshtml | 6 +- .../Orchard.Modules/Scripts/features.admin.js | 2 +- .../Scripts/features.admin.min.js | 5 +- .../Views/Admin/Features.cshtml | 57 +++++++++---------- 5 files changed, 34 insertions(+), 38 deletions(-) diff --git a/src/Orchard.Web/Core/Navigation/Scripts/navigation-admin.js b/src/Orchard.Web/Core/Navigation/Scripts/navigation-admin.js index 347854cd5..08dc685de 100644 --- a/src/Orchard.Web/Core/Navigation/Scripts/navigation-admin.js +++ b/src/Orchard.Web/Core/Navigation/Scripts/navigation-admin.js @@ -42,7 +42,7 @@ // display a message on leave if changes have been made window.onbeforeunload = function (e) { - return leaveConfirmation; + return $("
").html(leaveConfirmation).text(); }; // cancel leaving message on save diff --git a/src/Orchard.Web/Core/Navigation/Views/Admin/Index.cshtml b/src/Orchard.Web/Core/Navigation/Views/Admin/Index.cshtml index bb81da637..9388e2ae4 100644 --- a/src/Orchard.Web/Core/Navigation/Views/Admin/Index.cshtml +++ b/src/Orchard.Web/Core/Navigation/Views/Admin/Index.cshtml @@ -134,12 +134,12 @@ @using (Script.Foot()) { } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Modules/Scripts/features.admin.js b/src/Orchard.Web/Modules/Orchard.Modules/Scripts/features.admin.js index ad88615d8..7fd4e0ae9 100644 --- a/src/Orchard.Web/Modules/Orchard.Modules/Scripts/features.admin.js +++ b/src/Orchard.Web/Modules/Orchard.Modules/Scripts/features.admin.js @@ -43,7 +43,7 @@ var force = actionLink.data("feature-force"); var dependants = actionLink.data("feature-dependants"); - if (!dependants || /^\s*$/.test(dependants) || confirm(confirmDisableMessage + "\n\n" + dependants)) { + if (!dependants || /^\s*$/.test(dependants) || confirm($("
").html(confirmDisableMessage + "\n\n" + dependants).text())) { $("[name='submit.BulkExecute']").val("yes"); $("[name='featureIds']").val(featureId); diff --git a/src/Orchard.Web/Modules/Orchard.Modules/Scripts/features.admin.min.js b/src/Orchard.Web/Modules/Orchard.Modules/Scripts/features.admin.min.js index dc6081236..1b85a1176 100644 --- a/src/Orchard.Web/Modules/Orchard.Modules/Scripts/features.admin.min.js +++ b/src/Orchard.Web/Modules/Orchard.Modules/Scripts/features.admin.min.js @@ -1,4 +1 @@ -$(function(){var n=function(){var n=$(".bulk-actions-wrapper").addClass("visible"),t=$(".switch-for-switchable");t.prepend(n);$("#search-box").focus().keyup(function(){var n=$(this).val(),t;if(n==""){$("li.category").show();$("li.feature:hidden").show();return}$("li.feature").each(function(){var t=$(this),i=t.find("h3:first").text();i.toLowerCase().indexOf(n.toLowerCase())>=0?t.show():t.hide()});$("li.category:hidden").show();t=$("li.category:not(:has(li.feature:visible))").hide()})},t=function(){$("li.feature h3").on("change","input[type='checkbox']",function(){var n=$(this).is(":checked"),t=$(this).parents("li.feature:first");t.toggleClass("selected",n)})},i=function(){$("li.feature .actions").on("click","a[data-feature-action]",function(n){var t=$(this),r=t.data("feature-id"),u=t.data("feature-action"),f=t.data("feature-force"),i=t.data("feature-dependants");(!i||/^\s*$/.test(i)||confirm(confirmDisableMessage+"\n\n"+i))&&($("[name='submit.BulkExecute']").val("yes"),$("[name='featureIds']").val(r),$("[name='bulkAction']").val(u),$("[name='force']").val(f),t.parents("form:first").submit());n.preventDefault()})};n();t();i()}); -/* -//# sourceMappingURL=features.admin.min.js.map -*/ \ No newline at end of file +$(function(){var n=function(){var n=$(".bulk-actions-wrapper").addClass("visible"),t=$(".switch-for-switchable");t.prepend(n);$("#search-box").keyup(function(){var n=$(this).val(),t;if(n==""){$("li.category").show();$("li.feature:hidden").show();return}$("li.feature").each(function(){var t=$(this),i=t.find("h3:first").text();i.toLowerCase().indexOf(n.toLowerCase())>=0?t.show():t.hide()});$("li.category:hidden").show();t=$("li.category:not(:has(li.feature:visible))").hide()})},t=function(){$("li.feature h3").on("change","input[type='checkbox']",function(){var n=$(this).is(":checked"),t=$(this).parents("li.feature:first");t.toggleClass("selected",n)})},i=function(){$("li.feature .actions").on("click","a[data-feature-action]",function(n){var t=$(this),r=t.data("feature-id"),u=t.data("feature-action"),f=t.data("feature-force"),i=t.data("feature-dependants");(!i||/^\s*$/.test(i)||confirm($("
").html(confirmDisableMessage+"\n\n"+i).text()))&&($("[name='submit.BulkExecute']").val("yes"),$("[name='featureIds']").val(r),$("[name='bulkAction']").val(u),$("[name='force']").val(f),t.parents("form:first").submit());n.preventDefault()})};n();t();i()}); \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Modules/Views/Admin/Features.cshtml b/src/Orchard.Web/Modules/Orchard.Modules/Views/Admin/Features.cshtml index 36295b52f..ec6da75a3 100644 --- a/src/Orchard.Web/Modules/Orchard.Modules/Views/Admin/Features.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Modules/Views/Admin/Features.cshtml @@ -16,29 +16,29 @@ @if (Model.Features.Any()) { using (Html.BeginFormAntiForgeryPost()) { - @Html.Hidden("submit.BulkExecute") - @Html.Hidden("force", true) - @Html.Hidden("featureIds") -
-
- - -
-
- - - -
-
+ @Html.Hidden("submit.BulkExecute") + @Html.Hidden("force", true) + @Html.Hidden("featureIds") +
+
+ + +
+
+ + + +
+
-
    - @{ +
      + @{ var featureGroups = Model.Features.OrderBy(f => f.Descriptor.Category, new DoghouseComparer("Core")).GroupBy(f => f.Descriptor.Category).ToList(); foreach (var featureGroup in featureGroups) { if (!featureGroup.Any(x => Model.IsAllowed(x.Descriptor.Extension))) { @@ -98,8 +98,7 @@ @featureName - } - else { + } else { @featureName } @@ -138,14 +137,14 @@ }
    } - } -
} + } + } using (Script.Foot()) { } } \ No newline at end of file From ef2abe14cbb35b3f42c8a1b6f9c606b1c299071d Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Fri, 22 May 2015 15:37:51 +0200 Subject: [PATCH 09/13] #5306: Implemented a background HttpContext factory. This change instantiates an actual HttpContext object during background sweeps so that Razor templates using Html Helpers (that require HttpContext.Current to be not-null) won't fai lwhen being rendered. --- src/Orchard/BackgroundHttpContext.cs | 38 ++++++++++++++++++++++++ src/Orchard/Mvc/HttpContextAccessor.cs | 39 +++++++++++++++++++++++++ src/Orchard/Mvc/IHttpContextAccessor.cs | 33 +-------------------- src/Orchard/Mvc/MvcModule.cs | 2 +- src/Orchard/Orchard.Framework.csproj | 2 ++ src/Orchard/Tasks/BackgroundService.cs | 10 +++++-- 6 files changed, 88 insertions(+), 36 deletions(-) create mode 100644 src/Orchard/BackgroundHttpContext.cs create mode 100644 src/Orchard/Mvc/HttpContextAccessor.cs diff --git a/src/Orchard/BackgroundHttpContext.cs b/src/Orchard/BackgroundHttpContext.cs new file mode 100644 index 000000000..1b4f68f3b --- /dev/null +++ b/src/Orchard/BackgroundHttpContext.cs @@ -0,0 +1,38 @@ +using System.IO; +using System.Web; +using Orchard.Settings; + +namespace Orchard { + /// + /// A factory class that creates an HttpContext instance and initializes the HttpContext.Current property with that instance. + /// This is useful when rendering views from a background thread, as some Html Helpers access HttpContext.Current directly, thus preventing a NullReferenceException. + /// + public class BackgroundHttpContextFactory : IBackgroundHttpContextFactory { + public const string IsBackgroundHttpContextKey = "IsBackgroundHttpContext"; + private readonly ISiteService _siteService; + public BackgroundHttpContextFactory(ISiteService siteService) { + _siteService = siteService; + } + + public HttpContext CreateHttpContext() { + var url = _siteService.GetSiteSettings().BaseUrl; + var httpContext = new HttpContext(new HttpRequest("", url, ""), new HttpResponse(new StringWriter())); + + httpContext.Items[IsBackgroundHttpContextKey] = true; + + return httpContext; + } + + public void InitializeHttpContext() { + if (HttpContext.Current != null) + return; + + HttpContext.Current = CreateHttpContext(); + } + } + + public interface IBackgroundHttpContextFactory : IDependency { + HttpContext CreateHttpContext(); + void InitializeHttpContext(); + } +} diff --git a/src/Orchard/Mvc/HttpContextAccessor.cs b/src/Orchard/Mvc/HttpContextAccessor.cs new file mode 100644 index 000000000..615d527df --- /dev/null +++ b/src/Orchard/Mvc/HttpContextAccessor.cs @@ -0,0 +1,39 @@ +using System; +using System.Web; + +namespace Orchard.Mvc { + public class HttpContextAccessor : IHttpContextAccessor { + private HttpContextBase _httpContext; + + public HttpContextBase Current() { + var httpContext = GetStaticProperty(); + return !IsBackgroundHttpContext(httpContext) ? new HttpContextWrapper(httpContext) : _httpContext; + } + + public void Set(HttpContextBase httpContext) { + _httpContext = httpContext; + } + + private static bool IsBackgroundHttpContext(HttpContext httpContext) { + return httpContext == null || httpContext.Items.Contains(BackgroundHttpContextFactory.IsBackgroundHttpContextKey); + } + + private static HttpContext GetStaticProperty() { + var httpContext = HttpContext.Current; + if (httpContext == null) { + return null; + } + + try { + // The "Request" property throws at application startup on IIS integrated pipeline mode. + if (httpContext.Request == null) { + return null; + } + } + catch (Exception) { + return null; + } + return httpContext; + } + } +} \ No newline at end of file diff --git a/src/Orchard/Mvc/IHttpContextAccessor.cs b/src/Orchard/Mvc/IHttpContextAccessor.cs index 91208d314..462887fee 100644 --- a/src/Orchard/Mvc/IHttpContextAccessor.cs +++ b/src/Orchard/Mvc/IHttpContextAccessor.cs @@ -1,39 +1,8 @@ -using System; -using System.Web; +using System.Web; namespace Orchard.Mvc { public interface IHttpContextAccessor { HttpContextBase Current(); void Set(HttpContextBase httpContext); } - - public class HttpContextAccessor : IHttpContextAccessor { - private HttpContextBase _httpContext; - - public HttpContextBase Current() { - var httpContext = GetStaticProperty(); - return httpContext != null ? new HttpContextWrapper(httpContext) : _httpContext; - } - - public void Set(HttpContextBase httpContext) { - _httpContext = httpContext; - } - - private HttpContext GetStaticProperty() { - var httpContext = HttpContext.Current; - if (httpContext == null) { - return null; - } - - try { - if (httpContext.Request == null) { - return null; - } - } - catch (Exception) { - return null; - } - return httpContext; - } - } } diff --git a/src/Orchard/Mvc/MvcModule.cs b/src/Orchard/Mvc/MvcModule.cs index 1e0c49ce6..e1e8c19eb 100644 --- a/src/Orchard/Mvc/MvcModule.cs +++ b/src/Orchard/Mvc/MvcModule.cs @@ -28,7 +28,7 @@ namespace Orchard.Mvc { return false; try { - // The "Request" property throws at application startup on IIS integrated pipeline mode + // The "Request" property throws at application startup on IIS integrated pipeline mode. var req = HttpContext.Current.Request; } catch (Exception) { diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index a7093e72b..65099a4cc 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -317,6 +317,7 @@ + @@ -644,6 +645,7 @@ + diff --git a/src/Orchard/Tasks/BackgroundService.cs b/src/Orchard/Tasks/BackgroundService.cs index 8956595bd..b952a6a26 100644 --- a/src/Orchard/Tasks/BackgroundService.cs +++ b/src/Orchard/Tasks/BackgroundService.cs @@ -16,24 +16,28 @@ namespace Orchard.Tasks { public class BackgroundService : IBackgroundService { private readonly IEnumerable _tasks; private readonly ITransactionManager _transactionManager; + private readonly IBackgroundHttpContextFactory _backgroundHttpContextFactory; private readonly string _shellName; - private readonly IContentManager _contentManager; public BackgroundService( IEnumerable tasks, ITransactionManager transactionManager, ShellSettings shellSettings, - IContentManager contentManager) { + IContentManager contentManager, + IBackgroundHttpContextFactory backgroundHttpContextFactory) { + _tasks = tasks; _transactionManager = transactionManager; + _backgroundHttpContextFactory = backgroundHttpContextFactory; _shellName = shellSettings.Name; - _contentManager = contentManager; Logger = NullLogger.Instance; } public ILogger Logger { get; set; } public void Sweep() { + _backgroundHttpContextFactory.InitializeHttpContext(); + foreach(var task in _tasks) { var taskName = task.GetType().FullName; From 53e58f60fe2f588e76fcad3e26442eded8cc60f3 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Wed, 27 May 2015 16:36:51 +0200 Subject: [PATCH 10/13] #5306: Minor refactoring of background http context factory. --- ...oundHttpContext.cs => BackgroundHttpContextFactory.cs} | 7 +------ src/Orchard/IBackgroundHttpContextFactory.cs | 8 ++++++++ src/Orchard/Orchard.Framework.csproj | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) rename src/Orchard/{BackgroundHttpContext.cs => BackgroundHttpContextFactory.cs} (89%) create mode 100644 src/Orchard/IBackgroundHttpContextFactory.cs diff --git a/src/Orchard/BackgroundHttpContext.cs b/src/Orchard/BackgroundHttpContextFactory.cs similarity index 89% rename from src/Orchard/BackgroundHttpContext.cs rename to src/Orchard/BackgroundHttpContextFactory.cs index 1b4f68f3b..9935e7dfc 100644 --- a/src/Orchard/BackgroundHttpContext.cs +++ b/src/Orchard/BackgroundHttpContextFactory.cs @@ -30,9 +30,4 @@ namespace Orchard { HttpContext.Current = CreateHttpContext(); } } - - public interface IBackgroundHttpContextFactory : IDependency { - HttpContext CreateHttpContext(); - void InitializeHttpContext(); - } -} +} \ No newline at end of file diff --git a/src/Orchard/IBackgroundHttpContextFactory.cs b/src/Orchard/IBackgroundHttpContextFactory.cs new file mode 100644 index 000000000..1437518f8 --- /dev/null +++ b/src/Orchard/IBackgroundHttpContextFactory.cs @@ -0,0 +1,8 @@ +using System.Web; + +namespace Orchard { + public interface IBackgroundHttpContextFactory : IDependency { + HttpContext CreateHttpContext(); + void InitializeHttpContext(); + } +} diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index 65099a4cc..c4cd91d8f 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -148,6 +148,7 @@ + @@ -645,7 +646,7 @@ - + From 3d25ca42c93e7418480dba361520c103c2fb0847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Ros?= Date: Thu, 28 May 2015 12:50:07 -0700 Subject: [PATCH 11/13] #5327: Fixing Orchard.Roles web.config file --- src/Orchard.Web/Modules/Orchard.Roles/Styles/Web.config | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Styles/Web.config b/src/Orchard.Web/Modules/Orchard.Roles/Styles/Web.config index 6e8ebec36..817198995 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Styles/Web.config +++ b/src/Orchard.Web/Modules/Orchard.Roles/Styles/Web.config @@ -1,14 +1,5 @@ - - - - - - - - - From ee0bd03c0441c91a57b168966d12c1a86986f2b3 Mon Sep 17 00:00:00 2001 From: Lombiq Date: Sat, 30 May 2015 01:37:31 +0200 Subject: [PATCH 12/13] Fixing that Output Cache storage providers could fail with an ObjectDisposedException due to a deferred delegate execution causing the usage of dependencies from a disposed lifetime scope. --- .../Filters/OutputCacheFilter.cs | 51 +++++++++++-------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs b/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs index a92736ae1..0bc2d4337 100644 --- a/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs +++ b/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs @@ -213,30 +213,39 @@ namespace Orchard.OutputCache.Filters { response.Filter = captureStream; captureStream.Captured += (output) => { try { - var cacheItem = new CacheItem() { - CachedOnUtc = _now, - Duration = cacheDuration, - GraceTime = cacheGraceTime, - Output = output, - ContentType = response.ContentType, - QueryString = filterContext.HttpContext.Request.Url.Query, - CacheKey = _cacheKey, - InvariantCacheKey = _invariantCacheKey, - Url = filterContext.HttpContext.Request.Url.AbsolutePath, - Tenant = _shellSettings.Name, - StatusCode = response.StatusCode, - Tags = new[] { _invariantCacheKey }.Union(contentItemIds).ToArray() - }; + // Since this is a callback any call to injected dependencies can result in an Autofac exception: "Instances + // cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed." + // To prevent access to the original lifetime scope a new work context scope should be created here and dependencies + // should be resolved from it. - // Write the rendered item to the cache. - _cacheStorageProvider.Remove(_cacheKey); - _cacheStorageProvider.Set(_cacheKey, cacheItem); + using (var scope = _workContextAccessor.CreateWorkContextScope()) { + var cacheItem = new CacheItem() { + CachedOnUtc = _now, + Duration = cacheDuration, + GraceTime = cacheGraceTime, + Output = output, + ContentType = response.ContentType, + QueryString = filterContext.HttpContext.Request.Url.Query, + CacheKey = _cacheKey, + InvariantCacheKey = _invariantCacheKey, + Url = filterContext.HttpContext.Request.Url.AbsolutePath, + Tenant = scope.Resolve().Name, + StatusCode = response.StatusCode, + Tags = new[] { _invariantCacheKey }.Union(contentItemIds).ToArray() + }; - Logger.Debug("Item '{0}' was written to cache.", _cacheKey); + // Write the rendered item to the cache. + var cacheStorageProvider = scope.Resolve(); + cacheStorageProvider.Remove(_cacheKey); + cacheStorageProvider.Set(_cacheKey, cacheItem); - // Also add the item tags to the tag cache. - foreach (var tag in cacheItem.Tags) { - _tagCache.Tag(tag, _cacheKey); + Logger.Debug("Item '{0}' was written to cache.", _cacheKey); + + // Also add the item tags to the tag cache. + var tagCache = scope.Resolve(); + foreach (var tag in cacheItem.Tags) { + tagCache.Tag(tag, _cacheKey); + } } } finally { From 917fd8425f7dde5aa15c2e5dce890754eff0a9bf Mon Sep 17 00:00:00 2001 From: Lombiq Date: Sun, 31 May 2015 18:15:29 +0200 Subject: [PATCH 13/13] Fixing ComponentNotRegisteredException during setup, fixes #4159 Added fix by jtkech. --- src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs b/src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs index 397536b20..a40f66d9e 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs +++ b/src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs @@ -67,6 +67,7 @@ namespace Orchard.Setup { builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().InstancePerMatchingLifetimeScope("shell"); builder.RegisterType().As().SingleInstance(); + builder.RegisterType().As().InstancePerLifetimeScope(); // setup mode specific implementations of needed service interfaces builder.RegisterType().As().InstancePerLifetimeScope(); @@ -101,6 +102,12 @@ namespace Orchard.Setup { } + internal class SetupBackgroundService : IBackgroundService { + public void Sweep() { + // Don't run any background service in setup mode. + } + } + [UsedImplicitly] class SafeModeText : IText { public LocalizedString Get(string textHint, params object[] args) {