简体   繁体   中英

Empty Request.Files at mvc 4.0 and ajax upload bigger than 4mb

I tried to implement a simple file upload with ajax and progressbar to my mvc 4.0 controller with VS2013 and .net Framework 4.5

Uploads up to 4MB work as expected, but more than 4MB doesn't work! The Controller method is called but Request.Files is empty then!

If I try files bigger than the maxAllowedContentLength the request fails as expected.

Here is my code:

Client side solution found on http://www.matlus.com/html5-file-upload-with-progress/#codeListing6

Server Side solution self implementet:

[HttpPost]
public JsonResult Upload()
{
    var name = Request.Files[0].FileName;
    var result = new {};

    return Json(result, JsonRequestBehavior.AllowGet);
}

Web.config:

...
<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="2147483647" />
        </requestFiltering>
    </security>
    ...

Try this in web config

<system.web>
    <httpRuntime maxRequestLength="2147483647" executionTimeout="1100" />
</system.web>

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