I am new to nopCommerce. I downloaded and installed version 4.0 nopCommerce. While in configuration, under payment restrictions, I attempted to restrict all payment methods in all countries except US. When I clicked save, the system crashed and gave me the below error exception in 2017 Visual Studio Community.
The error occurred in the ApplicationBuilderExtensions.cs
Line: 81
The error message: System.IO.InvalidDataException: 'Form value count limit 1024 exceeded.'
System.IO.InvalidDataException occurred HResult=0x80131501 Message=Form value count limit 1024 exceeded. Source=Nop.Web.Framework StackTrace: at Nop.Web.Framework.Infrastructure.Extensions.ApplicationBuilderExtensions.<>c.<UseNopExceptionHandler>b__1_1(HttpContext context) in C:\Users\jimth_000\Source\repos\NopCommerce\Presentation\Nop.Web.Framework\Infrastructure\Extensions\ApplicationBuilderExtensions.cs:line 81 at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__6.MoveNext()
I tried checking off one column at a time. The error occurs after 4 columns are saved. Even after restarting the application this occurs. I have also uninstalled and reinstalled the application several times and this error still occurs.
Can anyone please provide some guidance on why this happens and how to prevent this?
Resolved Below Error: The error message: System.IO.InvalidDataException: 'Form value count limit 1024 exceeded.' Solution:
You have to create Filter Attribute. So create below Filter in Nop.Web.Framework.Mvc.Filters
------------------------------------------------------------------------------------------- using Microsoft.AspNetCore.Mvc.Filters; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace Nop.Web.Framework.Mvc.Filters { 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)); } } } }
After create filter, Add this filter on "MethodRestrictionsSave" Method Like Below.
[AdminAntiForgery(true)] [RequestFormSizeLimit(valueCountLimit: 2048)] [HttpPost, ActionName("MethodRestrictions")] public virtual IActionResult MethodRestrictionsSave(IFormCollection form) { if (!_permissionService.Authorize(StandardPermissionProvider.ManagePaymentMethods)) return AccessDeniedView();