简体   繁体   English

ASP.NET 核心捕获 HTTP 状态码 413 载荷太大/请求实体太大

[英]ASP.NET Core Capture HTTP Status Code 413 Payload Too Large / Request Entity Too Large

In Statup.cs -> Configure:在 Statup.cs -> 配置中:

app.UseStatusCodePagesWithReExecute("/StatusCodeError/{0}");

I was trying to capture this one: 413 Payload Too Large , Previously called " Request Entity Too Large "我试图捕获这个: 413 Payload Too Large ,以前称为“请求实体太大

I just cant seem to get any middleware to fire when a 413 is triggered, guess IIS looks after it?当 413 被触发时,我似乎无法让任何中间件触发,猜猜 IIS 会照顾它吗?

Just want to know the best approach to handle this as don't really want to show the user the default iis error message.只是想知道处理此问题的最佳方法,因为不想向用户显示默认的 iis 错误消息。

I tried adding this in to the web.config, but then this stopped other status codes working eg 404:我尝试将其添加到 web.config 中,但随后这停止了其他状态代码的工作,例如 404:

<httpErrors errorMode="Custom" existingResponse="Replace">
  <remove statusCode="413" />
  <error statusCode="413" path="/StatusCodeError/413" responseMode="Redirect" />
</httpErrors>

Thank you谢谢

I figured out what was happening why the status code error page was not displaying.我弄清楚了状态代码错误页面未显示的原因。

I added this to StatusCodeError.cshtml.cs我将其添加到 StatusCodeError.cshtml.cs

public void OnPost(int statusCode)
{
      OnGet(statusCode);
}

All my code was in the OnGet, but because the status code 413 was triggered on a POST nothing was happening.我所有的代码都在 OnGet 中,但是因为状态代码 413 是在 POST 上触发的,所以什么也没有发生。

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

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