如何调整待上传的文件大小

如何调整待上传的文件大小,第1张

设置文件上传的最大大小

系统环境:win8

开发环境:asp.net mvc

功能:文件上传

在上传文件时,比较小的文件会直接上传成功,大的文件页面报错:“文件超过了最大请求长度”。

经过查明:

需要在配置文件里面设置文件上传限定的两个属性值:maxAllowedContentLength,maxRequestLength 允许上传文件的长度,和请求的长度,两个大小需要设置一致,如果不一致,则以请求长度为准。

The maximum request size in kilobytes. The default size is 4096 KB (4 MB). 默认请求长度只有4M. 设置的单位都为byte

<system.web>

<httpRuntime maxRequestLength="2147483647" executionTimeout="36000" delayNotificationTimeout="36000"/>

</system.web>

<system.webServer>

<security>

<requestFiltering>

<!--<requestLimits maxAllowedContentLength="1073741824"/>-->

<requestLimits maxAllowedContentLength="2147483648"/>

</requestFiltering>

</security>

</system.webServer>

以上是对某个站点或者某个应用上限制大小,配置的web.config

要以上配置有效的前提是,要确保applicationhost.config中对该项修改的权限已经放开。

applicationhost.config文件路径在 C:\Windows\System32\inetsrv\config 下

可通过如下设置进行更改:

modify the overrideModeDefault from "Deny" to "Allow" like so:

<sectionGroup name="system.webServer">

<sectionGroup name="security">

<section name="requestFiltering" overrideModeDefault="Allow" />

</sectionGroup>

</sectionGroup>

确认修改过applicationhost.config中上述设置以后,再进行web.config中的设置。

二: 也可以直接设置服务器级别的文件上传大小,在applicationhost.config文件中加上以下字段

<system.webServer>

<security>

<requestFiltering>

<requestLimits maxAllowedContentLength="2147483647" />

</requestFiltering>

<security>

<system.webServer>

也可以使用命令模式修改:

也可以使用命令行模式修改applicationhost.config:

%windir%\system32\inetsrv\appcmd set config -section:requestFiltering -requestLimits.maxAllowedContentLength:2147483647

命令模式尚未试过。

方法/步骤

本文以win2012下的IIS8.0为例。

鼠标移至桌面最最左下角,d出开始菜单,点击左键。

点击iis管理器,并选中您的网站。

点击“管理”下的“配置编辑器”。

设置上传超时时间限制。

点击下拉菜单节(S),选中system.web>httpRuntime

将executionTimeout的值设为00:30:00(即30分钟)

设置上传文件大小限制。

点击下拉菜单节(S),选中system.webServer>security>requestFiltering

展开requestlimits,将maxAllowedContentLength的值设为102400000(即100m)

注:这样修改直接就能生效,无需重启iis或者服务器。

也可以直接在网站根目录建一个web.config文件,用此方法可以直接省略前5步,web.config内容具体如下

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

<system.webServer>

<security>

<requestFiltering>

<requestLimits maxAllowedContentLength="102400000" />

</requestFiltering>

</security>

</system.webServer>

<system.web>

<httpRuntime executionTimeout="1800" />

</system.web>

</configuration>


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/tougao/11664824.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-17
下一篇2023-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存