zoukankan      html  css  js  c++  java
  • 如何自定义上传文件大小限制

    大多数网站都具备上传文件的功能,拥护可以利用此功能从客户端向服务器上传文件.默认情况下,上传文件的大小不能超过4MB.如果超过此界限边不能上传.  那么如何自定义上传文件限制呢?

    解答:

    asp.net通过修改Web.config和Machine.config文件对网站和网站目录进行配制.

    1)修改Web.config文件

      在web.config文件中添加<httpRuntime/>配制可以自定义上传文件大小限制.添加设置代码如下.

      <configuration>

        <system.web>

          <httpRuntime

              maxRequestLength="4096"  //此大小为默认值,此值可以根据需要改变

              executionTimeout="600"   //此值指定上传文件的有效时间为10分钟

            />

        </system.web>

     </configuration>

    2) 修改Machine.config文件

      在Microsoft.NET\Framework\v1.1.4322\CONFIG目录下找到Machine.config文件.打开Machine.config文件可以看到如下设置代码.

      <!--
            httpRuntime Attributes:
              executionTimeout="[seconds]" - time in seconds before request is automatically timed out
              maxRequestLength="[KBytes]" - KBytes size of maximum request length to accept
              useFullyQualifiedRedirectUrl="[true|false]" - Fully qualifiy the URL for client redirects
              minFreeThreads="[count]" - minimum number of free thread to allow execution of new requests
              minLocalRequestFreeThreads="[count]" - minimum number of free thread to allow execution of new local requests
              appRequestQueueLimit="[count]" - maximum number of requests queued for the application
              enableKernelOutputCache="[true|false]" - enable the http.sys cache on IIS6 and higher - default is true
              enableVersionHeader="[true|false]" - outputs X-AspNet-Version header with each request
            -->
            <httpRuntime
                executionTimeout="90"
                maxRequestLength="4096"
                useFullyQualifiedRedirectUrl="false"
                minFreeThreads="8"
                minLocalRequestFreeThreads="4"
                appRequestQueueLimit="100"
                enableVersionHeader="true"
            />

    上面的代码中executionTimeout属性用于指定上传操作的有效时间(单位秒).maxRequestLengh属性用于指定上传文件的最大字节,单位KB,此属性默认大小为4096KB(4MB).

  • 相关阅读:
    本周学习进度条2
    web—图表表示数据库中的数据
    Intern Day36
    计算机网络
    面试
    C++
    计算机网络
    腾讯PC客户端开发暑期实习一面
    TCP和UDP
    Intern Day34
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/702428.html
Copyright © 2011-2022 走看看