Maximum request size ASP.Net MVC

Asked

Viewed 6,487 times

8

I am uploading Image using Jquery.

I limited the image to 2mb, but sending a larger image of 2mb shows an exception saying Maximum request size exceeded.

That’s what I did:

function fileUpload() {
    
    $('#fileupload').fileupload();
    $('#fileupload').fileupload('option', {
        maxFileSize: 1024 * 1024,
        autoupload: true
    });

    var uploadFinished = function (e, data) {
        if (data.files[0].size > 2000000) { // 2mb
            $.notify("Faça o upload de uma imagem de até 2MB", "danger");
            jqXHR.abort();
            return
        }

        var img = $("#inpLogoNameNew").val();
        $("#imgLogo").show();
        $("#imgWhite").hide();
        $("#imgLogo").attr("src", (data.result.imgx64));
        $("#inpLogoNameNew").val(data.result.Name);

        if ($("#inpLogoNameOld").val() !== $("#inpLogoNameNew").val() &&
            img !== $("#inpLogoNameNew").val() &&
            img !== $("#inpLogoNameOld").val()) {
            deleteLogo(img);
        }

    };
    $('#fileupload')
        .bind('fileuploaddone', uploadFinished);
}
<form id="fileupload" action="@Url.Action("UploadFiles")" method="POST" enctype="multipart/form-data">
                    <span id="spanUpload" class="btn btn-primary btn-sm fileinput-button"><i class="icon-plus icon-white"></i><span>Foto</span>
                        <input id="inpLogo" type="file" name="files[]"/>
                    </span>
                </form>

  • take a look here... http://stackoverflow.com/questions/288612/how-to-increase-the-max-upload-file-size-in-asp-net

4 answers

10


In the Web.Config, define the following:

<configuration>
  ...
  <system.web>
    ...
    <httpRuntime maxRequestLength="1048576"/>
    ...
  </system.web>
  ...
  </system.webServer>
    ...
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
    </security>
    ...
  </system.webServer>
  ...
</configuration>

These are the highest values I’ve ever used (1 Gigabyte). Good to say:

  • maxAllowedContentLength is in bytes;
  • maxRequestLength is in kilobytes.
  • I have this same problem and could not solve using this code. any suggestion?

  • This code does not solve, it is necessary to change the maxRequestLength of the entrance httpRuntime as reported in other responses.

3

I had the same problem and could not solve with the Gypsy solution. I decided to insert the following code in the web.config:

<httpRuntime 
executionTimeout="90" 
maxRequestLength="4096" //aumentar o valor aqui
useFullyQualifiedRedirectUrl="false" 
minFreeThreads="8" 
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"
/>

I’ll keep it safe here to help other people too.

  • It would be good if you also detail what are the father tags, as I did in my reply.

2

In web config, there is already a configuration:

<system.web>
<httpRuntime targetFramework="4.5"/>
</system.web>

Just change it, it’ll stay that way:

<system.web>
<httpRuntime targetFramework="4.5" maxRequestLength="10485760"/>
</system.web>

That’s how it works

  • Talk Harry, it’s been a week since I’ve had this problem almost. Thank you for your help. God Bless Master Jedi.

  • @Marianeribeiro, and a pleasure to help!

1

Just you make the change in your web.config, thereby:

< system.web><br>
    < httpRuntime maxRequestLength="10240"/> <br>
< / system.web>

The value is set in kilobytes and the default is 4096, ie 4 megabytes. Above, for example, the maximum size was set to 10 megabytes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.