0

I'm use ABP Zero Core MVC template (ASP.Net Core 2.x, MVC, jQuery) version 4.2.0. When I try to upload a file using the AJAX to controller, I get an HTTP 404.13 error, which indicates that the maximum file size is exceeded. Here and here I found solutions to similar problem and try it solved so ajust, but they either do not fit the pattern used, or I'm doing something wrong.

How to increase the maximum upload file size in Zero Core?

// *.Web.Host\Startup\Program.cs 
// *.Web.Mvc\Startup\Program.cs
public static IWebHostBuilder CreateWebHostBuilder(string[] args) {
    return WebHost.CreateDefaultBuilder(args)
        .UseKestrel(options => { 
            // no effect...  I can only small files uploaded
            options.Limits.MaxRequestBodySize = 1024 * 1024 * 1024; 
        })
        .UseStartup<Startup>();
}
XelaNimed
  • 301
  • 5
  • 18
  • What other things have you tried so far? You may need a combination of techniques as this is not a limit in one location. – Kami Dec 18 '18 at 09:14
  • @Kami I tried to use the code specified above in the Program.cs files in * .Web.Mvc and * .Web.Host projects. – XelaNimed Dec 18 '18 at 09:21
  • Have you tried the settings at https://github.com/aspnet/Announcements/issues/267 ? – Kami Dec 18 '18 at 09:22
  • @Kami Global Config variant - no effect, RequestSizeLimit attribute variant - no effect, Middleware variant - I'm not found any file for this. – XelaNimed Dec 18 '18 at 10:02
  • Did you do these independently or at the same time? Also, you may need to change the IIS configuration in addition to these settings. – Kami Dec 18 '18 at 10:45
  • @Kami I tried the proposed solutions separately. Since the project is ASP.Net Core, then I can not understand what does it have to do with IIS? It seems to be used Kestrel or am I wrong? The project is launched yet from VisualStudio. – XelaNimed Dec 18 '18 at 10:59
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/185415/discussion-between-xelanimed-and-kami). – XelaNimed Dec 18 '18 at 11:58

3 Answers3

2

Have you tried to decorate the controller action with [RequestSizeLimit(YOUR_MAX_TOTAL_UPLOAD_SIZE)] along with the changes in Startup.cs?

services.Configure<FormOptions>(opt =>
{
    opt.MultipartBodyLengthLimit = YOUR_MAX_TOTAL_UPLOAD_SIZE;
});

btw, if you are planning to host the app on IIS, you can add web.config file to your project and configure the upload size there, rather than configuring it on the IIS server.

EDIT: as @XelaNimed's comment, adding the web.config file along with editing the startup.cs, got the code working.

<configuration>
  <location path="." inheritInChildApplications="false">
   <system.webServer>
     <handlers>
       <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
     </handlers>
     <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
       <environmentVariables />
     </aspNetCore>
   </system.webServer>
 </location>
 <system.webServer>
   <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="YOUR_BYTES" />
       </requestFiltering>
    </security>
  </system.webServer>
</configuration>
Hameed
  • 1,497
  • 9
  • 12
  • 1
    I tried to decorate the method with an `RequestSizeLimit` attribute, but the error `Multipart body length limit 134217728 exceeded` still occurs. The solution with editing the `*.Web.Mvc/Startup/Startup.cs` file and editing `*.Web.Mvc/web.config` works. Edit please your code, as in the answer above, since it is not obvious which files and methods need to be edited. – XelaNimed Dec 21 '18 at 10:29
0

Try this

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
  //add to beginning of the method... 
  services.Configure<FormOptions>(x =>
  {
      x.ValueLengthLimit = int.MaxValue;
      x.MultipartBodyLengthLimit = int.MaxValue;
      x.MultipartHeadersLengthLimit = int.MaxValue;
  });


}
Alper Ebicoglu
  • 8,884
  • 1
  • 49
  • 55
0

Exceeded Maximum File Size in web.config - How Can This Be Fixed?

I have encountered an issue with my web.config file on my web server (E:\\WebServer\\DBBweb\\web.config). I realized that the maximum file size limit was exceeded once again. Here are the steps I took to identify and solve the problem:

  1. I found that the size of the web.config file was 251KB, which is larger than the permitted maximum file size of 250KB.
  2. I opened the Registry Editor (Regedit) as an Administrator.
  3. I navigated to the key: HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\InetStp.
  4. I added a subkey named 'Configuration'.
  5. I added a DWORD value named MaxWebConfigFileSizeInKB and set its value to a number greater than 251KB.
  6. I then navigated to the key: HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\InetStp. This key is identical to the previous key but contains the Wow6432Node in the path.
  7. I repeated steps 4 and 5 for this key.
  8. I stopped and started the application pool.
  9. Lastly, I restarted the server.

This procedure had to be done for both keys because the website is utilizing 32-bit compatibility.

Despite this the team and I continue to advise against adding client services in the web.config. We suggest using an APIHANDLER instead, which functions as an extension of the web.config.

Could anyone provide additional solutions or confirm whether this is the most efficient way to handle the issue of exceeding maximum file size in the web.config? Also, could anyone shed light on the benefits of using an APIHANDLER over adding client services directly in the web.config?

Thank you in advance for your assistance.

AztecCodes
  • 1,130
  • 7
  • 23