Search code examples
asp.net-coreazure-web-app-servicerazor-pages

Increase upload limit on Azure Web Service / Razor Pages


I have a Razor Pages app with a file upload page. I want to allow up to 60 MB uploads on that page. I can get do this locally by adding a <requestLimits maxAllowedContentLength="62914560" /> tag to my local applicationhost.config file in the .vs directory, but that doesn't help the deploy.

Here's what I've tried

  1. Adding [RequestFormLimits(MultipartBodyLengthLimit = 60 * 1024 * 1024)] and [RequestSizeLimit(60 * 1024 * 1024)] to the PageModel for the page in question
  2. Adding services.Configure<FormOptions>(options => { options.MultipartBodyLengthLimit = 60 * 1024 * 1024; }); to my Startup.cs
  3. Adding a middleware handler with app.UseWhen(context => context.Request.Path.StartsWithSegments("/mypagepath"), appBuilder => { appBuilder.Features.Get<IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = null; });
  4. Adding a Web.config file to the root of the project with the <requestLimits> tag. If I deploy that file the whole app stops working.

Everything works locally but when I deploy to my Azure App Service, I get this error

The page was not displayed because the request entity is too large.


Solution

  • If you add web.config file, you don't need to add anything in your code.

    In .net core project, you also can use web.config file.

      <system.webServer>
        <security>
          <requestFiltering>
            <requestLimits maxAllowedContentLength="62914560" /> <!--60MB-->
          </requestFiltering>
        </security>
      </system.webServer>