Hi!
After upgrade to CMS 12 and using Windows Authentication we cannot longer upload even the smallest of picture, the exception below occurs;
Exception:
System.InvalidOperationException: The maximum request body size cannot be modified after the app has already started reading from the request body.
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.Microsoft.AspNetCore.Http.Features.IHttpMaxRequestBodySizeFeature.set_MaxRequestBodySize(Nullable`1 value)
at EPiServer.Cms.Shell.UI.Attributes.RespectFileSizeLimitConfigurationAttribute.OnAuthorization(AuthorizationFilterContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at ElmahCore.Mvc.ErrorLogMiddleware.InvokeAsync(HttpContext context)
at ElmahCore.Mvc.ErrorLogMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.ResponseCaching.ResponseCachingMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Found this in the console:
The store was queried with a [string] but the entity id is a [undefined]
If found this so it looks like Optimizely is setting the size if there is a UploadOption
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class RespectFileSizeLimitConfigurationAttribute : Attribute, IAuthorizationFilter, IFilterMetadata, IOrderedFilter
{
public int Order { get; set; } = 899;
public void OnAuthorization(AuthorizationFilterContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
UploadOptions service = context.HttpContext.RequestServices.GetService<UploadOptions>();
if (service != null)
{
context.HttpContext.Features.Get<IHttpMaxRequestBodySizeFeature>()!.MaxRequestBodySize = service.FileSizeLimit;
}
}
}
A bug maybe?
Any ideas why this occours?
Thanks!
/Kristoffer