ASP. NET upload file maximum adjustment

Source: Internet
Author: User

First, the easiest to find is the configuration under Web. config:

    <!-- MAXREQUESTLENGTH=50MB  -    <  targetframework= "4.5.2"  maxrequestlength= "51200"/>

This setting increases the requested size from the default 4MB (4096KB) to 50MB (51200KB).

However, if you just set this, you will find that your maximum upload size will stop at 28.6MB, the larger the file upload, will return 404.13, indicating that the content length is too large.

The reason is that the default setting for IIS limits the value of maxAllowedContentLength.

<name= "RequestLimits"><name= " maxAllowedContentLength "  type=" UINT "  defaultvalue=" 30000000 "/ >

This value is set in Iis_schema.xml. (will affect the entire computer)

Iisexpress:iisexpress run path, C:\Program Files (x86) \iis Express\config\schema\iis_schema.xml
IIS7, 8:c:\windows\system32\inetsrv\config\schema\iis_schema.xml

If you modify this value does not take effect, two possible, one is currently running Iisexpress/iis not shutdown/restart. One is that there is an additional configuration in Web. config (as described in the following article).

However, in order to avoid always modifying the global values and affecting other Web sites on the same server, we can also configure them in Web. config.

  <system.webserver>    <!--iisexpress:c:\users\username\documents\iisexpress\config\applicationhost.config IIS7, 8:c:\windows\system32\ Inetsrv\config\applicationhost.config <section name= "requestfiltering" overridemodedefault= "Allow"/> Over            This configuration section will not take effect until the Ridemodedefault value is set to allow. It can also be set in Iis_schema.xml. (will affect the entire computer) iisexpress:iisexpress running path, C:\Program Files (x86) \iis Express\config\schema\iis_schema.xml IIS7, 8:c:\      Windows\system32\inetsrv\config\schema\iis_schema.xml Modify Defaultvalue= "30000000" (28.6MB) to the desired value. <element name= "requestlimits" ><attribute name= "maxallowedcontentlength" type= "UINT" defaultValue= " 30000000 "/> -    <Security>      <requestfiltering>        <!--MAXALLOWEDCONTENTLENGTH=100MB -        <requestlimitsmaxAllowedContentLength= "104857600"></requestlimits>      </requestfiltering>    </Security>

In order for this content to take effect, you need to configure allow inheritance, search for <section name= "requestfiltering" overridemodedefault= "allowed" in ApplicationHost.config >, make sure that the value is allow.

Iisexpress:c:\users\username\documents\iisexpress\config\applicationhost.config
IIS7, 8:c:\windows\system32\inetsrv\config\applicationhost.config

Resources:

Http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits

Http://www.cnblogs.com/henryhappier/archive/2010/09/20/1832098.html

https://msdn.microsoft.com/en-us/library/ms689462 (v=vs.90). aspx

ASP. NET upload file maximum adjustment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.