{"id":1044,"date":"2016-11-02T09:22:55","date_gmt":"2016-11-02T03:52:55","guid":{"rendered":"http:\/\/stepbystepschools.net\/?p=1044"},"modified":"2016-11-02T09:22:55","modified_gmt":"2016-11-02T03:52:55","slug":"invaliddataexception-form-key-or-value-length-limit-2048-exceeded-asp-net-mvc-core","status":"publish","type":"post","link":"https:\/\/www.stepbystepschools.net\/?p=1044","title":{"rendered":"InvalidDataException: Form key or value length limit 2048 exceeded :- ASP.NET MVC core."},"content":{"rendered":"<p>One of our students got the following error while making a huge post to the ASP.NET MVC core WebAPI. So the error is very clear, ASP.NET does not allow to post you data which have value and key length above 2048 and if you want to do it then you need to explicitly enable the same.<\/p>\n<p><img loading=\"lazy\" src=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2016\/11\/Response.png\" alt=\"response\" width=\"628\" height=\"192\" class=\"aligncenter size-full wp-image-1045\" srcset=\"https:\/\/www.stepbystepschools.net\/wp-content\/uploads\/2016\/11\/Response.png 628w, https:\/\/www.stepbystepschools.net\/wp-content\/uploads\/2016\/11\/Response-300x92.png 300w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/p>\n<p>For the same we wrote a simple filter as shown below , which allows post of  huge data.<\/p>\n<pre>[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]\r\npublicclassRequestFormSizeLimitAttribute : Attribute, IAuthorizationFilter, IOrderedFilter\r\n    {\r\nprivatereadonlyFormOptions _formOptions;\r\n\r\npublicRequestFormSizeLimitAttribute(intvalueCountLimit)\r\n        {\r\n            _formOptions = newFormOptions()\r\n            {\r\n\r\nKeyCountLimit = valueCountLimit,\r\nKeyLengthLimit = valueCountLimit\r\n            };\r\n        }\r\n\r\npublicint Order { get; set; }\r\n\r\npublicvoidOnAuthorization(AuthorizationFilterContext context)\r\n        {\r\nvar features = context.HttpContext.Features;\r\nvarformFeature = features.Get<IFormFeature>();\r\n\r\nif (formFeature == null || formFeature.Form == null)\r\n            {\r\n\/\/ Request form has not been read yet, so set the limits\r\nfeatures.Set<IFormFeature>(newFormFeature(context.HttpContext.Request, _formOptions));\r\n            }\r\n        }\r\n    }\r\n<\/pre>\n<p>Once you have written this attribute you can decorate on the WebAPI on which you want the post to happen as shown in the below code.<\/p>\n<pre>[RequestFormSizeLimit(valueCountLimit: 10000, Order = 1)]\r\n [Route(\"api\/[controller]\")]\r\npublicclassPatientController : Controller\r\n {}\r\n<\/pre>\n<p>Do not miss our next ASP.NET MVC batch coming week in Mumbai<br \/>\n<a target=\"_blank\" href=\"http:\/\/stepbystepschools.net\/?page_id=315\">http:\/\/stepbystepschools.net\/?page_id=315<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of our students got the following error while making a huge post to the ASP.NET MVC core WebAPI. So the error is very clear, ASP.NET does not allow to post you data which have value and key length above &hellip; <a href=\"https:\/\/www.stepbystepschools.net\/?p=1044\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[74,1,3,75],"tags":[25,90,89],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>InvalidDataException: Form key or value length limit 2048 exceeded :- ASP.NET MVC core. - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.stepbystepschools.net\/?p=1044\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"InvalidDataException: Form key or value length limit 2048 exceeded :- ASP.NET MVC core. - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai\" \/>\n<meta property=\"og:description\" content=\"One of our students got the following error while making a huge post to the ASP.NET MVC core WebAPI. So the error is very clear, ASP.NET does not allow to post you data which have value and key length above &hellip; Continue reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.stepbystepschools.net\/?p=1044\" \/>\n<meta property=\"og:site_name\" content=\"Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai\" \/>\n<meta property=\"article:published_time\" content=\"2016-11-02T03:52:55+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2016\/11\/Response.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sukesh Marla\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.stepbystepschools.net\/#website\",\"url\":\"https:\/\/www.stepbystepschools.net\/\",\"name\":\"Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai\",\"description\":\"MVC 5\/Core, AngularJS 1.x, 2.0, 4.0, Design Pattern, Architecture, SSIS, SSAS, SSRS, Data Science, Big data, Hadoop classroom training\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.stepbystepschools.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.stepbystepschools.net\/?p=1044#primaryimage\",\"url\":\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2016\/11\/Response.png\",\"contentUrl\":\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2016\/11\/Response.png\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.stepbystepschools.net\/?p=1044#webpage\",\"url\":\"https:\/\/www.stepbystepschools.net\/?p=1044\",\"name\":\"InvalidDataException: Form key or value length limit 2048 exceeded :- ASP.NET MVC core. - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai\",\"isPartOf\":{\"@id\":\"https:\/\/www.stepbystepschools.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.stepbystepschools.net\/?p=1044#primaryimage\"},\"datePublished\":\"2016-11-02T03:52:55+00:00\",\"dateModified\":\"2016-11-02T03:52:55+00:00\",\"author\":{\"@id\":\"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/88d563b9535849b699d9b5efa09d559c\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.stepbystepschools.net\/?p=1044#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.stepbystepschools.net\/?p=1044\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.stepbystepschools.net\/?p=1044#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.stepbystepschools.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"InvalidDataException: Form key or value length limit 2048 exceeded :- ASP.NET MVC core.\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/88d563b9535849b699d9b5efa09d559c\",\"name\":\"Sukesh Marla\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7f960ad602065c0f897d127d81b3adf8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7f960ad602065c0f897d127d81b3adf8?s=96&d=mm&r=g\",\"caption\":\"Sukesh Marla\"},\"sameAs\":[\"http:\/\/www.JustCompile.com\"],\"url\":\"https:\/\/www.stepbystepschools.net\/?author=2\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"InvalidDataException: Form key or value length limit 2048 exceeded :- ASP.NET MVC core. - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.stepbystepschools.net\/?p=1044","og_locale":"en_US","og_type":"article","og_title":"InvalidDataException: Form key or value length limit 2048 exceeded :- ASP.NET MVC core. - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai","og_description":"One of our students got the following error while making a huge post to the ASP.NET MVC core WebAPI. So the error is very clear, ASP.NET does not allow to post you data which have value and key length above &hellip; Continue reading &rarr;","og_url":"https:\/\/www.stepbystepschools.net\/?p=1044","og_site_name":"Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai","article_published_time":"2016-11-02T03:52:55+00:00","og_image":[{"url":"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2016\/11\/Response.png"}],"twitter_card":"summary_large_image","twitter_misc":{"Written by":"Sukesh Marla","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/www.stepbystepschools.net\/#website","url":"https:\/\/www.stepbystepschools.net\/","name":"Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai","description":"MVC 5\/Core, AngularJS 1.x, 2.0, 4.0, Design Pattern, Architecture, SSIS, SSAS, SSRS, Data Science, Big data, Hadoop classroom training","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.stepbystepschools.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.stepbystepschools.net\/?p=1044#primaryimage","url":"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2016\/11\/Response.png","contentUrl":"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2016\/11\/Response.png"},{"@type":"WebPage","@id":"https:\/\/www.stepbystepschools.net\/?p=1044#webpage","url":"https:\/\/www.stepbystepschools.net\/?p=1044","name":"InvalidDataException: Form key or value length limit 2048 exceeded :- ASP.NET MVC core. - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai","isPartOf":{"@id":"https:\/\/www.stepbystepschools.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.stepbystepschools.net\/?p=1044#primaryimage"},"datePublished":"2016-11-02T03:52:55+00:00","dateModified":"2016-11-02T03:52:55+00:00","author":{"@id":"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/88d563b9535849b699d9b5efa09d559c"},"breadcrumb":{"@id":"https:\/\/www.stepbystepschools.net\/?p=1044#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.stepbystepschools.net\/?p=1044"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.stepbystepschools.net\/?p=1044#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.stepbystepschools.net\/"},{"@type":"ListItem","position":2,"name":"InvalidDataException: Form key or value length limit 2048 exceeded :- ASP.NET MVC core."}]},{"@type":"Person","@id":"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/88d563b9535849b699d9b5efa09d559c","name":"Sukesh Marla","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7f960ad602065c0f897d127d81b3adf8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7f960ad602065c0f897d127d81b3adf8?s=96&d=mm&r=g","caption":"Sukesh Marla"},"sameAs":["http:\/\/www.JustCompile.com"],"url":"https:\/\/www.stepbystepschools.net\/?author=2"}]}},"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/posts\/1044"}],"collection":[{"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1044"}],"version-history":[{"count":4,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/posts\/1044\/revisions"}],"predecessor-version":[{"id":1049,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/posts\/1044\/revisions\/1049"}],"wp:attachment":[{"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1044"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1044"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1044"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}