In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to solve the problem of upload restrictions on Mvc files in ASP.NET Core, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
I. brief introduction
In ASP.NET Core MVC, the maximum upload file for file upload defaults to 20MB. If we want to upload some large files, we don't know how to set it up. How should we start without Web.Config?
Second, set the upload file size
1. Application level settin
We need to add the following code to the ConfigureServices method to set the file upload size limit to 60 MB.
Public void ConfigureServices (IServiceCollection services) {servicesConfigure (options = > {optionsMultipartBodyLengthLimit = 6000000;});}
2.Action level settin
In addition to the global settings above, we can also control a single Action by customizing Filter. The Filter code is as follows:
[AttributeUsage (AttributeTargetsClass | AttributeTargetsMethod, AllowMultiple = false, Inherited = true)] public class RequestFormSizeLimitAttribute: Attribute, IAuthorizationFilter, IOrderedFilter {private readonly FormOptions _ formOptions; public RequestFormSizeLimitAttribute (int valueCountLimit) {_ formOptions = new FormOptions () {ValueCountLimit = valueCountLimit};} public int Order {get; set;} public void OnAuthorization (AuthorizationFilterContext context) {var features = contextHttpContextFeatures; var formFeature = featuresGet () If (formFeature = = null | | formFeatureForm = = null) {/ / Request form has not been read yet, so set the limits featuresSet (new FormFeature (contextHttpContextRequest, _ formOptions));}
Because in ASP.NET Core MVC, what is different from the previous version is that the specific functions are encapsulated in various Feature (features), and the HttpContext context is just a container that can be managed by each feature. In this Filter, only Action is intercepted, and the FormFeature (responsible for form submission function) in HttpContext is reset to achieve the purpose of limiting the size of specific Action uploaded files.
The above is all the contents of this article entitled "how to solve the problem of upload restrictions on Mvc files in ASP.NET Core". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.