关于文件上传大小限制的总结

1.asp.net web.config 文件的配置:

<httpRuntime maxRequestLength="153600" executionTimeout="3600" />

150MB 一小时连接超时

以及 

<basicHttpBinding>节点下面

<binding 里面配置

maxBufferSize="153600" maxBufferPoolSize="524288" maxReceivedMessageSize="153600"

closeTimeout="01:00:00"
openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"

配置最大字节 超时时间

2.如果用了WCF做文件上传:

<system.serviceModel>
<services>
<!--name 提供服务的类名-->
<!--behaviorConfiguraron 指定相关的行为配置 -->
<service name="ZRQCommonFile.WCF.FileService"
behaviorConfiguration="ZRQCommonFile.WCF.FileServiceBehavior">
<!--address - 服务地址-->
<!--binding - 通信方式-->
<!--contract - 服务契约-->
<!--bindingConfiguration - 指定相关的绑定配置-->
<endpoint
address="Message/FileService"
binding="basicHttpBinding"
contract="ZRQCommonFile.WCF.IFileService"
bindingConfiguration="ZRQCommonFile.WCF.FileServiceBehavior" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:83/WCF/FileService"/>
</baseAddresses>
</host>
</service>
</services>

<bindings>
<basicHttpBinding>
<!--transferMode - 指示通道是使用流处理模式还是缓冲模式来传输请求和响应消息-->
<!--maxReceivedMessageSize - 在采用此绑定配置的通道上可接收的最大消息大小(单位:字节)157286400 150MB-->
<!--receiveTimeout - 在传输引发异常之前可用于完成读取操作的时间间隔-->
<binding
name="ZRQCommonFile.WCF.FileServiceBehavior"
transferMode="Streamed"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"
receiveTimeout="01:00:00" />

</basicHttpBinding>
<wsHttpBinding>
<!--transferMode - 指示通道是使用流处理模式还是缓冲模式来传输请求和响应消息-->
<!--maxReceivedMessageSize - 在采用此绑定配置的通道上可接收的最大消息大小(单位:字节)157286400 150MB-->
<!--receiveTimeout - 在传输引发异常之前可用于完成读取操作的时间间隔-->
<binding
name="ZRQCommonFile.WCF.FileServiceBehavior"
maxReceivedMessageSize="2147483647"
receiveTimeout="01:00:00" />
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ZRQCommonFile.WCF.FileServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

3.还有一个地方会限制到你的上传大小以及连接时间 IIS   ii7.5

IIS中有好几个地方配置大小的 具体的功能不知道,网上有这么几个

1.在《功能视图》 有个ASP 里面有个 最大请求实体主体限制

2.在《功能视图》 有个请求筛选   右边 编辑功能设置 允许最大内容长度 默认是30MB 我多加了一个0

3.上面两个都是针对网站的  下面是针对IIS的

修改IIS_schema.xml这个文件要先获得这个文件的控制权;

进入目录C:WindowsSystem32inetsrvconfigschema,修改文件IIS_schema.xml 权限:

进入IIS_schema.xml文件权限修改,选择”高级”

选择”所有者”

选中 administrators 确定

再进入权限编辑,修改administrators 完全控制

再去掉IIS_schema.xml的只读属性

然后记事本打开文件 找到 requestLimits 里面有个

attribute name="maxAllowedContentLength" type="uint" defaultValue="30000000"

我是增加了一个0  300MB 限制。

用WCF 做好文件上传,VS中 调试正常 上传小文件 大文件都正常,发布到IIS 只能上传 20MB 以下的文件

查了查IIS 限制的问题。更改了IIS 配置 解决。

原文地址:https://www.cnblogs.com/90nice/p/3487903.html