From d33aa6cdf5053613d95de17ff1d628637103054a Mon Sep 17 00:00:00 2001 From: Elitsa Marinovska Date: Mon, 11 May 2020 16:23:33 +0200 Subject: [PATCH] Updating the way we get UmbracoContext in RedirectToUmbracoPageResult.cs; removing the flushing in JsonNetResult.cs and adding necessary configuration for allowing sync operations needed in JsonNetResult.cs --- .../ActionResults/JsonNetResult.cs | 3 --- src/Umbraco.Web.UI.NetCore/Startup.cs | 11 +++++++++-- .../ActionResults/RedirectToUmbracoPageResult.cs | 10 +++++----- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Web.BackOffice/ActionResults/JsonNetResult.cs b/src/Umbraco.Web.BackOffice/ActionResults/JsonNetResult.cs index 24f4ec51b8..db5c7a8510 100644 --- a/src/Umbraco.Web.BackOffice/ActionResults/JsonNetResult.cs +++ b/src/Umbraco.Web.BackOffice/ActionResults/JsonNetResult.cs @@ -42,11 +42,8 @@ namespace Umbraco.Web.BackOffice.ActionResults { using var bodyWriter = new StreamWriter(response.Body); using var writer = new JsonTextWriter(bodyWriter) { Formatting = Formatting }; - var serializer = JsonSerializer.Create(SerializerSettings); serializer.Serialize(writer, Data); - - writer.Flush(); } return Task.CompletedTask; diff --git a/src/Umbraco.Web.UI.NetCore/Startup.cs b/src/Umbraco.Web.UI.NetCore/Startup.cs index 37440006aa..fb491e6d2c 100644 --- a/src/Umbraco.Web.UI.NetCore/Startup.cs +++ b/src/Umbraco.Web.UI.NetCore/Startup.cs @@ -2,6 +2,7 @@ using System; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -53,10 +54,16 @@ namespace Umbraco.Web.UI.BackOffice options.ShouldProfile = request => false; // WebProfiler determine and start profiling. We should not use the MiniProfilerMiddleware to also profile }); + // If using Kestrel: https://stackoverflow.com/a/55196057 + services.Configure(options => + { + options.AllowSynchronousIO = true; + }); + //Finally initialize Current // TODO: This should be moved to the UmbracoServiceProviderFactory when the container is cross-wired and then don't use the overload above to `out var factory` Current.Initialize( - factory.GetInstance (), + factory.GetInstance(), factory.GetInstance(), factory.GetInstance(), factory.GetInstance(), @@ -70,7 +77,7 @@ namespace Umbraco.Web.UI.BackOffice public void Configure(IApplicationBuilder app) { - // app.UseMiniProfiler(); + // app.UseMiniProfiler(); app.UseUmbracoRequest(); if (_env.IsDevelopment()) { diff --git a/src/Umbraco.Web.Website/ActionResults/RedirectToUmbracoPageResult.cs b/src/Umbraco.Web.Website/ActionResults/RedirectToUmbracoPageResult.cs index dfc28f1412..3d06ca101e 100644 --- a/src/Umbraco.Web.Website/ActionResults/RedirectToUmbracoPageResult.cs +++ b/src/Umbraco.Web.Website/ActionResults/RedirectToUmbracoPageResult.cs @@ -1,21 +1,21 @@ using System; -using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; -using System.Text; using System.Threading.Tasks; using System.Web; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.Extensions.DependencyInjection; -using Umbraco.Composing; +using Umbraco.Core; using Umbraco.Core.IO; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Routing; namespace Umbraco.Web.Website.ActionResults { + /// + /// Redirects to an Umbraco page by Id or Entity + /// public class RedirectToUmbracoPageResult : IActionResult { private IPublishedContent _publishedContent; @@ -55,7 +55,7 @@ namespace Umbraco.Web.Website.ActionResults if (!(_publishedContent is null)) return _publishedContent; //need to get the URL for the page - _publishedContent = _umbracoContextAccessor.UmbracoContext.Content.GetById(_pageId); + _publishedContent = _umbracoContextAccessor.GetRequiredUmbracoContext().Content.GetById(_pageId); return _publishedContent; }