Asp.net Core 2.0 RequestSizeLimit属性不起作用

编程入门 行业动态 更新时间:2024-10-10 12:17:25
本文介绍了Asp Core 2.0 RequestSizeLimit属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在Asp core 2.0中创建一个网站,该网站允许上传文件.我很快遇到了30MB上传限制的问题,并从服务器收到了404响应.低于此限制,一切正常.

I'm creating a website in Asp core 2.0 which allows files to be uploaded. I quickly came across the problem of the 30MB upload limit and receive a 404 response from the server. Below this limit everything works fine.

我在网络上找到了许多这样的解决方案: 增加Asp.Net core中的上传文件大小.我的问题是我无法使用此解决方案,并且在30MB上方时仍会收到404响应.

I found a number of solutions on the web like this one: Increase upload file size in Asp.Net core. My problem is that I cannot get this solution to work and I'm still getting the 404 response when over 30MB.

我的电话是一个ajax电话,它是这样的:

My call is an ajax one and goes like this:

function uploadMedia(isPhoto, files) { var type; if (isPhoto) { type = "i"; } else { type = "v"; } var data = new FormData(); if (files.length > 0) { for (idx = 0; idx < files.length; idx++) { if (files[idx].size < 1074790400) { data.append("fileImage" + idx, files[idx]); } else { BootstrapDialog.show({ type: BootstrapDialog.TYPE_WARNING, title: "Validation Error", message: "The maximum file size for images is 1GB. Please resize your image and upload again.", buttons: [ { label: "OK", action: function(dialogItself) { dialogItself.close(); } } ] }); } } $.ajax({ url: "/api/article/uploadfile/" + type, type: "POST", processData: false, contentType: false, dataType: false, data: data, success: function(jsonData) { refreshUploadedImages(jsonData, isPhoto); } }); } } function rotateImageAnticlockwise(element) { var id = $(element).attr("data-id"); var mediaData = getMediaData(id, true); $.ajax({ url: "/api/article/rotateMedia/a/p/" + mediaData.fileId + "/" + mediaData.rotation, type: "POST", processData: false, contentType: false, success: function(jsonData) { refreshRotatedImage(jsonData); } }); }

然后我的服务器端方法具有以下属性:

Then my server-side method has attributes like this:

[HttpPost] [RequestSizeLimit(1074790400)] [Route("api/article/uploadfile/{mediaType}")] public async Task<IActionResult> UploadFile(string mediaType)

有人可以看到我在做什么错吗?这让我发疯了!!!

Can anyone see what I'm doing wrong? This is driving me mad!!!

推荐答案

对于其他有相同问题的人,这就是答案.

For anyone else with the same problem, this is the answer.

马克·拉弗勒(Mark LaFleur)的答案是正确的方向,但web.config缺少关键部分.

Mark LaFleur's answer was the right direction but the web.config was missing a crucial section.

我得到了帮助,但是此网页解释了有关Asp Core中的web.config文件的更多信息: ASP.NET核心模块配置参考

I was helped but this webpage that explains more about the web.config file in Asp Core: ASP.NET Core Module configuration reference

要停止此错误,您需要创建一个具有以下内容的web.config文件:

To stop this error you need to create a web.config file with the following content:

<?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" /> </handlers> <security> <requestFiltering> <!-- This will handle requests up to 50MB --> <requestLimits maxAllowedContentLength="52428800" /> </requestFiltering> </security> </system.webServer> </configuration>

更多推荐

Asp.net Core 2.0 RequestSizeLimit属性不起作用

本文发布于:2023-11-14 03:52:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586136.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   属性   net   Asp   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!