ฉันได้รับข้อผิดพลาดเกินความยาวสูงสุดที่กำหนดเมื่อฉันพยายามอัปโหลดวิดีโอในเว็บไซต์ของฉัน
ฉันจะแก้ไขสิ่งนี้ได้อย่างไร
ฉันได้รับข้อผิดพลาดเกินความยาวสูงสุดที่กำหนดเมื่อฉันพยายามอัปโหลดวิดีโอในเว็บไซต์ของฉัน
ฉันจะแก้ไขสิ่งนี้ได้อย่างไร
คำตอบ:
หากคุณใช้ IIS สำหรับโฮสต์แอปพลิเคชันของคุณขนาดไฟล์อัปโหลดเริ่มต้นคือ 4MB หากต้องการเพิ่มโปรดใช้ส่วนด้านล่างในweb.config-
<configuration>
    <system.web>
        <httpRuntime maxRequestLength="1048576" />
    </system.web>
</configuration>สำหรับ IIS7 ขึ้นไปคุณจะต้องเพิ่มบรรทัดด้านล่าง:
 <system.webServer>
   <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
   </security>
 </system.webServer>หมายเหตุ :
maxRequestLengthวัดเป็นกิโลไบต์maxAllowedContentLengthวัดเป็นไบต์ ซึ่งเป็นเหตุผลที่ค่าแตกต่างในตัวอย่างการตั้งค่านี้ (ทั้งสองมีค่าเท่ากับ 1 GB)
Web.configแทนที่จะเป็นหนึ่งในViewsโฟลเดอร์
                    ฉันไม่คิดว่ามันถูกกล่าวถึงที่นี่ แต่เพื่อให้การทำงานนี้ฉันต้องระบุค่าทั้งสองนี้ใน web.config:
ใน system.web
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />และใน system.webServer
<security>
    <requestFiltering>
        <requestLimits maxAllowedContentLength="1073741824" />
    </requestFiltering>
</security>สำคัญ : ค่าทั้งสองนี้ต้องตรงกัน ในกรณีนี้การอัปโหลดสูงสุดของฉันคือ 1024 เมกะไบต์
maxRequestLength มี1048576 KILOBYTESและ maxAllowedContentLength มี1073741824 ไบต์
ฉันรู้ว่ามันชัดเจน แต่มันง่ายที่จะมองข้าม
web.configไฟล์รูทโปรเจ็กต์
                    อาจเป็นเรื่องน่าสังเกตว่าคุณอาจต้องการ จำกัด การเปลี่ยนแปลงนี้กับ URL ที่คุณคาดว่าจะใช้สำหรับการอัปโหลดแทนที่จะเป็นไซต์ทั้งหมดของคุณ
<location path="Documents/Upload">
  <system.web>
    <!-- 50MB in kilobytes, default is 4096 or 4MB-->
    <httpRuntime maxRequestLength="51200" />
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <!-- 50MB in bytes, default is 30000000 or approx. 28.6102 Mb-->
        <requestLimits maxAllowedContentLength="52428800" /> 
      </requestFiltering>
    </security>
  </system.webServer>
</location>และในกรณีที่มีใครบางคนกำลังมองหาวิธีที่จะจัดการกับข้อยกเว้นนี้และแสดงคำอธิบายที่มีความหมายกับผู้ใช้ (เช่น "คุณกำลังอัปโหลดไฟล์ที่มีขนาดใหญ่เกินไป"):
//Global.asax
private void Application_Error(object sender, EventArgs e)
{
    var ex = Server.GetLastError();
    var httpException = ex as HttpException ?? ex.InnerException as HttpException;
    if(httpException == null) return;
    if (((System.Web.HttpException)httpException.InnerException).WebEventCode == System.Web.Management.WebEventCodes.RuntimeErrorPostTooLarge)
    {
        //handle the error
        Response.Write("Too big a file, dude"); //for example
    }
}(จำเป็นต้องใช้ ASP.NET 4 หรือใหม่กว่า)
HttpContext.Current.ClearError()จำเป็นต้องอนุญาตให้Response.Redirect()ทำงานได้อย่างถูกต้อง ในแง่ของweb.configมันทำงานได้กับแอตทริบิวต์ของmaxRequestLength httpRuntime
                    onchangeเหตุการณ์ที่ปุ่มอัปโหลดและเปรียบเทียบขนาดไฟล์อัปโหลดกับขีด จำกัด การอัปโหลดสูงสุด
                    ถ้าคุณไม่สามารถอัปเดตการตั้งค่าไฟล์ HttpContext.Current.Request.GetBufferlessInputStream(true)แต่ควบคุมรหัสที่อัปโหลดไฟล์จัดการใช้
trueค่าสำหรับdisableMaxRequestLengthพารามิเตอร์บอกกรอบที่จะไม่สนใจข้อ จำกัด คำขอกำหนดค่า
สำหรับคำอธิบายโดยละเอียดไปที่https://msdn.microsoft.com/en-us/library/hh195568(v=vs.110).aspx
มีองค์ประกอบใน web.config เพื่อกำหนดขนาดสูงสุดของไฟล์ที่อัปโหลด:
<httpRuntime 
    maxRequestLength="1048576"
  />เพื่อสรุปคำตอบทั้งหมดในที่เดียว:
<system.web>
  <httpRuntime targetFramework="4.5.2" maxRequestLength="1048576"/>
</system.web>
<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="1073741824" />
    </requestFiltering>
  </security>
</system.webServer>กฎ:
หมายเหตุ:
ข้อมูลเพิ่มเติมMSDN
maxRequestLength (ความยาวเป็น KB) ที่นี่เช่น ฉันเลือก 1024 (1MB) maxAllowedContentLength (ความยาวเป็นไบต์) ควรเหมือนกับ maxRequestLength ของคุณ (1048576 ไบต์ = 1MB)
<system.web>
   <httpRuntime maxRequestLength="1024" executionTimeout="3600" />
</system.web>
<system.webServer>
   <security>
      <requestFiltering>
          <requestLimits maxAllowedContentLength="1048576"/>
      </requestFiltering>
   </security>
</system.webServer>มันรบกวนฉันหลายวันเช่นกัน ฉันแก้ไขไฟล์ Web.config แต่มันไม่ทำงาน ปรากฎว่ามีไฟล์ Web.config สองไฟล์ในโครงการของฉันและฉันควรแก้ไขไฟล์หนึ่งในไดเรกทอรีROOTไม่ใช่ไฟล์อื่น หวังว่านี่จะเป็นประโยชน์
หากคุณมีคำขอไปยังแอปพลิเคชันในไซต์ตรวจสอบให้แน่ใจว่าคุณตั้งค่า maxRequestLength ในรูท web.config maxRequestLength ใน web.config ของแอปพลิเคชันดูเหมือนจะถูกละเว้น
httpRuntime maxRequestLength="###และrequestLimits maxAllowedContentLengthในการกำหนดค่าเว็บที่ระดับรูทไม่ใช่ในระดับแอปย่อย
                    ฉันถูกสะดุดด้วยความจริงที่ว่าไฟล์ web.config ของเรามีหลายส่วน system.web: มันทำงานเมื่อฉันเพิ่ม <httpRuntime maxRequestLength = "1048576" /> ในส่วน system.web ที่ระดับการกำหนดค่า
ฉันต้องแก้ไขC:\Windows\System32\inetsrv\config\applicationHost.configไฟล์และเพิ่ม<requestLimits maxAllowedContentLength="1073741824" />ในส่วนท้ายของ ...
<configuration>
    <system.webServer>
        <security>
            <requestFiltering>มาตรา.
applicationHost.configจากโครงการของคุณเองควรแทนที่เหล่านี้ดังนั้นผมจึงไม่เห็นความจำเป็นในการปรับเปลี่ยน
                    ฉันสามารถเพิ่มเพื่อกำหนดค่าเว็บที่ยังไม่ได้คอมไพล์
<system.web> 
  <httpRuntime maxRequestLength="1024" executionTimeout="3600" /> 
  <compilation debug="true"/> 
</system.web> 
<security> 
  <requestFiltering> 
    <requestLimits maxAllowedContentLength="1048576"/> 
  </requestFiltering> 
</security>executionTimeoutแอตทริบิวต์มีอะไรจะทำอย่างไรกับสิ่งที่จะถามและไม่ไม่compilationแท็ก