版本10上传MP3遇Maximum request length exceeded错误,web.config配置无效求助
Hey there, let's sort out this frustrating upload error you're facing. That Maximum request length exceeded exception is super common when dealing with file uploads in ASP.NET, and even if you've tweaked your web.config already, there's a good chance you missed one of the key settings. Let's break down exactly what you need to check and update:
1. Update ASP.NET's Request Length Limit (in <system.web>)
First, make sure you've set the maxRequestLength in the <httpRuntime> section—this is the ASP.NET-level limit, measured in KB. For example, if you want to allow 15MB files, that's 15 * 1024 = 15360 KB:
<system.web> <!-- Allow 15MB uploads, with a 1-hour execution timeout to avoid upload timeouts --> <httpRuntime maxRequestLength="15360" executionTimeout="3600" /> </system.web>
The executionTimeout is optional but helpful for larger files, as it gives the upload process enough time to complete.
2. Set IIS's Request Filtering Limit (in <system.webServer>)
This is the one people often forget! IIS has its own separate limit measured in bytes, and it will block the request before it even reaches ASP.NET if you don't set this. For the same 15MB example, that's 15 * 1024 * 1024 = 15728640 bytes:
<system.webServer> <security> <requestFiltering> <!-- Match the size you set in maxRequestLength (15MB here) --> <requestLimits maxAllowedContentLength="15728640" /> </requestFiltering> </security> </system.webServer>
Critical note: Make sure the values here align with your maxRequestLength setting—don't set one to 15MB and the other to 4MB, or you'll still hit the error.
3. Check Action-Level Size Limits (If Using ASP.NET MVC)
If your upload action has a [RequestSizeLimit] attribute, this will override your web.config settings. Double-check that the value here is large enough for your MP3 files:
[HttpPost] // Allow 15MB uploads for this specific action [RequestSizeLimit(15728640)] public ActionResult UploadMP3(HttpPostedFileBase mp3File) { // Your upload logic here }
If you don't have this attribute, no problem—just skip this step.
4. Verify IIS Site-Level Settings
Sometimes the IIS site itself has a hardcoded limit that overrides your web.config. To check:
- Open IIS Manager, navigate to your site
- Click on Request Filtering in the Features View
- Click Edit Feature Settings on the right-hand side
- Make sure the Maximum allowed content length (bytes) matches the value you set in
web.config
Final Step: Restart Your App Pool
After making all these changes, restart your IIS application pool (or the entire IIS service) to ensure the new settings take effect.
This error happens because both ASP.NET and IIS have default small upload limits (around 4MB) to prevent abuse. By updating both of these settings, you'll lift those restrictions for your MP3 files.
内容的提问来源于stack exchange,提问作者Syed Hassaan Ahmed

