简体   繁体   中英

ASP.NET Request.Files empty with bad connection only

I have a file upload page allowing to upload multiple documents.

When I use it with a reasonably good connection, it works fine: for each individual file, my controller action is called and Request.Files does contain one single file.

However, when I simulate a bad connection using the developer tools (GPRS speed), when my controller action is called, Request.Files is empty.

I also tried with a medium connection (3G), and I got a mix of both: two files were successfuly uploaded and I did have one file in Request.Files for each of them, and the other two failed with Request.Files being empty.

Is this a normal behaviour? What I would like to know is if there is something wrong in my code, or if I'm wasting my time trying to fix something that is not avoidable.

All the questions I saw about this issue indicate that I should specify multipart/form-data for the enctype attribute of the form, but this is not a solution to my issue since it works just fine with a good connection.

Thank you.

EDIT:

@Gunnarhawk, this is how I perform the AJAX call:

return $.ajax({
    url: '@Url.Action("GetUploadedFileList", "Process", new { claimId = @claimId })',
    method: 'POST',
    contentType: "application/json; charset=utf-8",
    dataType: 'html',
    cache: false,
    data: dataJson, // Object as JSON text
    processData: false,
    traditional: true,
    success: function (response) {
        // Stuff...
    },
    error: function () {
        // Stuff...
    }
});

You could try to increase the execution timeout or max request length (to allow larger file uploads and for the page to run longer).

<httpRuntime maxRequestLength="byte size limit" executionTimeout="timeout in seconds" />

See the docs on maxRequestLength

The maximum request size in kilobytes. The default size is 4096 KB (4 MB).

And the docs on executionTimeout

A TimeSpan value that indicates the allowed execution time for the request.

I believe the time for executionTimeout is in seconds, so if you set it to 300, that is 5 minutes.

Doing this can allow a public application to be attacked by a malicious user, by trying to upload really large files, so be aware.

You can use the <location href="path"> element to scope the changes to a specific page in your application. See more on location in the Microsoft Docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM