sco*_*foy 5 .net c# asp.net iis web-services
我有一个使用 .net 4.5.2 的较旧的 ASP.NET API Web 服务,并且我将一个包含 base64 图像的对象发布到我的控制器,没有任何问题。现在,当我尝试发布包含更多更大图像的数据时,问题就出现了,并且收到 413 请求实体太大错误。我一直在查找东西并尝试了我在网上能找到的所有东西,但没有运气。我想要上传大约 10MB 大小的文件。让我相信其与服务器相关的一件事是,当在 IIS Express 下运行该服务时,我可以在本地上传大文件。
我尝试将 MaxRequestLength 和 MaxAllowableContentLength 添加到 Web 配置中。
<system.web>
<!-- tell IIS to let large requests through -->
<httpRuntime maxRequestLength="52428800" />
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="52428800" />
</requestFiltering>
</security>
Run Code Online (Sandbox Code Playgroud)
我还在 IIS v6.2 中对 Windows 2012 R2 服务器进行了更改,以允许更大的文件。我还调整了服务器上的 UploadReadAhead 值。
我的 API 配置类没有什么特别的。
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
}
}
Run Code Online (Sandbox Code Playgroud)
我的配置中针对此服务的绑定
<webHttpBinding>
<binding name="SecureServerBindingWithUserNameRest" maxReceivedMessageSize="52428800">
<readerQuotas maxArrayLength="10485760" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" proxyCredentialType="None" />
</security>
</binding>
<binding name="webHttpTransportSecurityRest">
<security mode="Transport" />
</binding>
</webHttpBinding>
Run Code Online (Sandbox Code Playgroud)
您可以尝试这个解决方案,尝试增加上传大小限制。IIS 在 applicationHost.config 和 web.config 文件中使用 uploadReadAheadSize 参数。
system.webServer然后serverRuntimeuploadReadAheadSize为2147483647| 归档时间: |
|
| 查看次数: |
10330 次 |
| 最近记录: |