Merge pull request #8747 from AndyButland/feature/avoid-sync-io-exception-on-image-render
Resolves issue with rendering back-office media selections when synchronous IO is not allowed.
This commit is contained in:
@@ -3,15 +3,16 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc.ActionConstraints;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Extensions;
|
||||
using Umbraco.Web.BackOffice.ModelBinders;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Umbraco.Web.BackOffice.Controllers
|
||||
{
|
||||
@@ -102,7 +103,11 @@ namespace Umbraco.Web.BackOffice.Controllers
|
||||
// IMPORTANT: Ensure the requestBody can be read multiple times.
|
||||
routeContext.HttpContext.Request.EnableBuffering();
|
||||
|
||||
var body = _requestBody ??= routeContext.HttpContext.Request.GetRawBodyString();
|
||||
// We need to use the asynchronous method here if synchronous IO is not allowed (it may or may not be, depending
|
||||
// on configuration in UmbracoBackOfficeServiceCollectionExtensions.AddUmbraco()).
|
||||
// We can't use async/await due to the need to override IsValidForRequest, which doesn't have an async override, so going with
|
||||
// this, which seems to be the least worst option for "sync to async" (https://stackoverflow.com/a/32429753/489433).
|
||||
var body = _requestBody ??= Task.Run(() => routeContext.HttpContext.Request.GetRawBodyStringAsync()).GetAwaiter().GetResult();
|
||||
|
||||
var jToken = JsonConvert.DeserializeObject<JToken>(body);
|
||||
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.BackOffice;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Core.Serialization;
|
||||
using Umbraco.Infrastructure.BackOffice;
|
||||
@@ -23,7 +15,6 @@ using Umbraco.Web.Common.Security;
|
||||
|
||||
namespace Umbraco.Extensions
|
||||
{
|
||||
|
||||
public static class BackOfficeServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -79,8 +79,6 @@ namespace Umbraco.Extensions
|
||||
request.Body.Seek(0, SeekOrigin.Begin);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static async Task<string> GetRawBodyStringAsync(this HttpRequest request, Encoding encoding = null)
|
||||
|
||||
Reference in New Issue
Block a user