陋室铭
永远也不要停下学习的脚步(大道至简至易)

posts - 2169,comments - 570,views - 413万

大多数网站都具备上传文件的功能,拥护可以利用此功能从客户端向服务器上传文件.默认情况下,上传文件的大小不能超过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).

posted on   宏宇  阅读(753)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
< 2007年4月 >
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 1 2 3 4 5
6 7 8 9 10 11 12

点击右上角即可分享
微信分享提示