您的位置:首页 > 其它

如何自定义上传文件大小限制

2007-03-16 16:51 477 查看
大多数网站都具备上传文件的功能,拥护可以利用此功能从客户端向服务器上传文件.默认情况下,上传文件的大小不能超过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).
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: