简体   繁体   English

响应:413 请求实体太大

[英]response: 413 Request Entity Too Large

When POSTing a request which can contain one or more files (as base64 string) I get this error response:当发布一个可以包含一个或多个文件(作为 base64 字符串)的请求时,我收到以下错误响应:

ERROR 2018-11-22 09:54:18,244 [13 ] Mvc.ExceptionHandling.AbpExceptionFilter - The remote server returned an unexpected response: (413) Request Entity Too Large.错误 2018-11-22 09:54:18,244 [13] Mvc.ExceptionHandling.AbpExceptionFilter - 远程服务器返回意外响应:(413)请求实体太大。 System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (413) Request Entity Too Large. System.ServiceModel.ProtocolException:远程服务器返回意外响应:(413) 请求实体太大。 at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result) at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass1_0.b__0(IAsyncResult asyncResult) --- End of stack trace from previous location where exception was thrown --- at ...在 System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result) 在 System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result) 在 System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult 结果)在 System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass1_0.b__0(IAsyncResult asyncResult) --- 从上一个抛出异常的位置开始的堆栈跟踪结束 --- 在 ...

I have searched on how to resolve this but I get redirected to WCF solutions all the time.我已经搜索了如何解决这个问题,但我一直被重定向到 WCF 解决方案。

I have added the following to the web.config of my WebApi project but it doesn't seem to make a difference.我已将以下内容添加到我的 WebApi 项目的 web.config 中,但它似乎没有什么区别。

<configuration>
  <system.webServer>
    ....
    <asp>
      <limits maxRequestEntityAllowed="2147483648"/>
    </asp>
    <serverRuntime uploadReadAheadSize="2147483647" />
  </system.webServer>
</configuration>

Can anyone help me or point me to the right resource?任何人都可以帮助我或为我指出正确的资源吗?

There are two limits you need to change.您需要更改两个限制。 Kestrel and IIS.红隼和 IIS。

You can change the MaxRequestBodySize limit of Kestrel in Program.cs.您可以在 Program.cs 中更改 Kestrel 的 MaxRequestBodySize 限制。

public static IWebHost BuildWebHost(string[] args)
{
    return WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .UseKestrel(options =>
        {
            options.Limits.MaxRequestBodySize = long.MaxValue;
        })
        .UseIISIntegration()
        .Build();
}

And the limit for IIS can be changed in web.config:并且可以在 web.config 中更改 IIS 的限制:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="2147483648" />
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

For me I had to do in the web.config setting using maxAllowedContentLength and also an attribute on the action that was reading the file.对我来说,我必须在 web.config 设置中使用 maxAllowedContentLength 以及读取文件的操作的属性。 I'm working on a .NET Core 3 application hosted on IIS.我正在开发一个托管在 IIS 上的 .NET Core 3 应用程序。

Web.config:网页配置:

<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="2147483648" />
        </requestFiltering>
    </security>
    ...
</system.webServer>

Attribute on the Action of the Controller:控制器动作的属性:

[DisableRequestSizeLimit]
[HttpPost]
public async Task<IActionResult> PostMyFile(){
   ...
}

I think, you may need to modify your web.config then add "maxRequestLength" and "maxAllowedContentLength"我认为,您可能需要修改您的 web.config,然后添加“maxRequestLength”和“maxAllowedContentLength”

<system.web>
    <compilation debug="true" targetFramework="4.5.2"/>
    <httpRuntime targetFramework="4.5.2" maxRequestLength="50240" executionTimeout="600"/> <!-- in Kb  -->
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="52428800" /> <!-- in byte (50 Mb) -->                                               
      </requestFiltering>
   </security>

When POSTing a request which can contain one or more files (as base64 string) I get this error response:当发布一个可以包含一个或多个文件(作为base64字符串)的请求时,我得到以下错误响应:

ERROR 2018-11-22 09:54:18,244 [13 ] Mvc.ExceptionHandling.AbpExceptionFilter - The remote server returned an unexpected response: (413) Request Entity Too Large.错误2018-11-22 09:54:18,244 [13] Mvc.ExceptionHandling.AbpExceptionFilter-远程服务器返回了意外的响应:(413)请求实体太大。 System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (413) Request Entity Too Large. System.ServiceModel.ProtocolException:远程服务器返回了意外的响应:(413)请求实体太大。 at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result) at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass1_0.b__0(IAsyncResult asyncResult) --- End of stack trace from previous location where exception was thrown --- at ...在System.ServiceModel.Channels.ServiceChannel.EndCall(String action,Object [] outs,在System.Servicetime.AsyncResult.End [TAsyncResult](IAsyncResult result)) IAsyncResult结果)位于System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator。<> c__DisplayClass1_0.b__0(IAsyncResult asyncResult)---从上次引发异常的位置开始的堆栈跟踪--- ...

I have searched on how to resolve this but I get redirected to WCF solutions all the time.我已经搜索过如何解决此问题的方法,但是我一直都被重定向到WCF解决方案。

I have added the following to the web.config of my WebApi project but it doesn't seem to make a difference.我在WebApi项目的web.config中添加了以下内容,但似乎没有什么不同。

<configuration>
  <system.webServer>
    ....
    <asp>
      <limits maxRequestEntityAllowed="2147483648"/>
    </asp>
    <serverRuntime uploadReadAheadSize="2147483647" />
  </system.webServer>
</configuration>

Can anyone help me or point me to the right resource?谁能帮助我或指向我正确的资源?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM