Cannot upload media after upgrade, exception in RespectFileSizeLimitConfigurationAttribute

Vote:
 

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

#290720
Edited, Oct 28, 2022 9:49
Vote:
 

Let me forward this to the CMS UI team 

#290843
Oct 31, 2022 12:01
Vote:
 

Can you please contact support for a ticket? 

#290844
Oct 31, 2022 12:19
Vote:
 

@Quan, I have a support ticket. #1012199. I'm not sure if they tested on IIS or not.

We have a SqlBlobProvider but I have tested without it, using Optimizely standard, and still I can not upload the smallest of files. It is so strange.

Thanks! 

/Kristoffer

#290845
Oct 31, 2022 12:46
Vote:
 

Hi!

We use Elmah for error handling and if I don't use Elmah, it works just fine.

This is the package:
https://www.nuget.org/packages/ElmahCore

I will start to investigate what could be the problem.

Thanks!

/Kristoffer

#290852
Oct 31, 2022 14:36
Vote:
 

Adding the:

app.UseElmah();

at the end of the Configure method fixes the issue.

/Kristoffer

#295729
Feb 01, 2023 14:54
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.