c# - .NET Core 3.1 MVC Web 应用程序中的 413 错误
问题描述
我有一个 .Net Core MVC 3.1 Web 应用程序,我必须在其中上传一个文件,并且我希望该文件的最大大小为 100MB。我正在尝试使用 app.UseExceptionHandler 显示错误,但它不起作用。我什至使用了一个自定义中间件来尝试查看请求的去向,而它没有去那里。
启动.cs
//app.UseExceptionHandler("/Errores"); <-- Tryed this and all the ways with useStatusCode...
//if (env.IsDevelopment())
//{
// app.UseDeveloperExceptionPage();
//}
//else
//{
// // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
// app.UseHsts();
//}
app.Use(async (context, next) =>
{
//try
//{
await next(); <-- It doesn't even reach here
//}
//catch { }
if (context.Response.StatusCode == 413)
{
context.Request.Path = "/Error/404";
await next();
}
});
app.UseHttpsRedirection();
app.UseFileServer();
app.UseCookiePolicy();
app.UseRouting();
app.UseSession();
app.UseAuthentication();
// Add MVC to the request pipeline.
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Login}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "Errores",
pattern: "Errores/{action}",
defaults: new { controller = "Errores" });
});
控制器是这样的
public ActionResult PostAyuda([FromForm] AyudaRequest dataRequest)
{
有什么帮助吗?
解决方案
推荐阅读
- json - 需要为特定的 JSON 输出重写 Scala 代码
- jq - 使用 jq 专门处理空 JSON 数组
- android - 合并资源时无法编译值文件(来自两个不同依赖项的文件中的重复值
- javascript - 如何使 SectionList 仅在拉动刷新时显示刷新指示器
- c - C程序的目录结构是什么样的?
- javascript - 空函数改变数组
- c# - 如何通过选择另一个 ListView 中的项目来显示 ListView 中的元素?
- linux - Bash shell 脚本,如何在命令中使用管道
- android - 如何使用 JSON API 在 recyclerview 滚动上加载更多数据
- javascript - App Lab 的 readRecords() 更改元素的 ID