Home kellton

Main navigation

  • Services
    • Digital Business Services
      • AI & ML
        • Utilitarian AI
        • Predictive Analytics
        • Generative AI
        • Machine Learning
        • Data Science
        • RPA
      • Digital Experience
        • Product Strategy & Consulting
        • Product Design
        • Product Management
      • Product Engineering
        • Digital Application Development
        • Mobile Engineering
        • IoT & Wearables Solutions
        • Quality Engineering
      • Data & Analytics
        • Data Consulting
        • Data Engineering
        • Data Migration & Modernization
        • Analytics Services
        • Integration & API
      • Cloud Engineering
        • Cloud Consulting
        • Cloud Migration
        • Cloud Managed Services
        • DevSecOps
      • NextGen Services
        • Blockchain
        • Web3
        • Metaverse
        • Digital Signage Solutions
        • Spatial Computing
    • SAP
      • SAP Services
        • S/4HANA Implementations
        • SAP AMS Support
        • SAP Automation
        • SAP Security & GRC
        • SAP Value Added Solutions
        • Other SAP Implementations
      • View All Services
  • Platforms & Products
    • Audit.io
    • Kellton4Health
    • Kellton4NFT
    • Kellton4Commerce
    • KLGAME
    • tHRive
    • Optima
    • Our Data Accelerators
      • Data DigitalTwin
      • SmartScope
      • DataLift
      • SchemaLift
      • Reconcile360
    • View All Products
  • Industries
    • Fintech, Banking, Financial Services & Insurance
    • Retail, E-Commerce & Distribution
    • Pharma, Healthcare & Life Sciences
    • Non-Profit, Government & Education
    • Travel, Logistics & Hospitality
    • HiTech, SaaS, ISV & Communications
    • Manufacturing, Automotive & Chemicals
    • Oil,Gas & Mining
    • Energy & Utilities
    • View All Industries
  • Insights
    • Blogs
    • Brochures
    • Success Stories
    • News / Announcements
    • Webinars
    • White Papers
  • Careers
    • Life At Kellton
    • Jobs
  • About
    • About Us
    • Our Partners
    • Our Leadership
    • Testimonials
    • Analyst Recognitions
    • Investors
    • Privacy-Policy
    • Contact Us
    • Our Delivery Centers
      • India Delivery Center
      • Europe Delivery Center
Search
  1. Home
  2. All Insights
  3. Blogs

How to submit a large number of Form-values in ASP.NET Core?

Product Engineering
November 16 , 2017
Posted By:
Kellton
linkedin
How to Submit a Large Number of Form-values in ASP.NET Core

Other recent blogs

Generative AI companies
ROI of Generative AI: Measuring its impact and value for your business
April 15 , 2025
Data migration cost
Breaking down the cost of Data Migration: Is it worth in 2025
April 10 , 2025
Data Migration trends 2025
Revealing top Data Migration trends and predictions to watch
April 01 , 2025

Let's talk

Reach out, we'd love to hear from you!

Image CAPTCHA
Get new captcha!
Enter the characters shown in the image.

HTML forms use either GET or POST method to submit form values to the server. The default method that most of the developers use is GET. When using the GET method, the form data is encoded in the URI as a query string. However, when using the POST method, the form data is placed in the request body.

If you wish to submit a form with a large number of elements (say 500 checkboxes) to our controller post method, then we get a runtime exception: InvalidDataException: Form value count limit 1024 exceeded. This exception means that ASP.NET Core does not allow us to post data which have value and key length above 1024. In order for the developer to explicitly enable this, we can use the following two ways:

  1. Application Level Changes:  Add the code in the startup.cs file as it will apply by default to all controller methods in the application.

    public void ConfigureServices(IServiceCollection services)
    { 
    services.Configure<FormOptions>(x => x.ValueCountLimit = 10000);
    services.AddMvc();
    }
  2. Method Level Changes: To increase the form size limit at the method level, we need to create a custom attribute say “RequestFormSizeLimitAttribute” in the controller post method.

  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 = context.HttpContext.Features;

            var formFeature = features.Get<IFormFeature>();

            if (formFeature == null || formFeature.Form == null)

            {

                features.Set<IFormFeature>(new FormFeature(context.HttpContext.Request,      

                _formOptions));

            }

        }

   }

Once the attribute is ready, we need to increase the key length which can be done in the following two ways:

  1. If no “Antiforgery” token is applied to the controller method, then the attribute can be applied directly on the method without specifying “order” of execution.

    [HttpPost]
    [RequestFormSizeLimit(valueCountLimit: 20000)]
    public IActionResult ActionSpecificLimits(YourModel model)
     
  2. If “Antiforgery” token is applied to the controller method, then we need to specify the order in which the attributes will be executed. If the order is not mentioned then the following exception is raised: “InvalidDataException: Form value count limit 1024 exceeded.”

It is mandatory to execute the “RequestFormSizeLimitAttribute” attribute before the “Antiforgery” token validation filter so that the limits are honored when the antiforgery validation filter tries to read the form. The form size limits only apply to this action.

[HttpPost]
[RequestFormSizeLimit(valueCountLimit: 20000, Order = 1)]
[ValidateAntiForgeryToken(Order = 2)]
public IActionResult ActionSpecificLimits(YourModel model)

LearnMore.jpg

Digital Transformation comprises the largest portfolio of work for Kellton Tech. Learn more about how our digital expertise is increasing ROI of clients looking for.NET Development Services.

Want to know more?

Quantum-proofing your business
Blog
Quantum-proofing your business: A critical security imperative
March 28 , 2025
Minimizing disruption in Product Modernization
Blog
Application Modernization Strategy: Revealing zero-disruption best practices
March 25 , 2025
Adaptive software development guide - Abstract thumbnail image
Blog
A detailed guide on adaptive software development
March 12 , 2025

North America: +1.844.469.8900

Asia: +91.124.469.8900

Europe: +44.203.807.6911

Email: ask@kellton.com

Footer menu right

  • Services
  • Platforms & Products
  • Industries
  • Insights

Footer Menu Left

  • About
  • News
  • Careers
  • Contact
LinkedIn Twitter Youtube
clutch Badge

© 2024 Kellton