@manhng

Welcome to my blog!

JsonResult MaxJsonLength

May 5, 2020 11:42

JsonResult MaxJsonLength (edit)

JsonResult

https://www.c-sharpcorner.com/UploadFile/2ed7ae/jsonresult-type-in-mvc/ (HAY HAY HAY)

Big Integer - Maximum

https://www.dotnetperls.com/biginteger (System.Numerics.BigInteger.Max)

https://docs.microsoft.com/en-us/dotnet/api/system.numerics.biginteger?view=netframework-4.5.2

https://www.dotnetperls.com/biginteger

JsonResult MaxJsonLength

https://stackoverflow.com/questions/5692836/maxjsonlength-exception-in-asp-net-mvc-during-javascriptserializer

http://rion.io/2013/04/28/handling-larger-json-string-values-in-net-and-avoiding-exceptions/

https://stackoverflow.com/questions/1151987/can-i-set-an-unlimited-length-for-maxjsonlength-in-web-config/

https://forums.asp.net/t/1751116.aspx (HAY HAY HAY)

https://forums.asp.net/t/1939039.aspx

Google Search

MVC 5 Increase Max JSON Length in POST Request

How to increase MaxJsonLength for JSON POST in MVC

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class MaxJsonSizeAttribute : ActionFilterAttribute
{
    // Default: 10 MB worth of one byte chars
    private int maxLength = 10 * 1024 * 1024;

    public int MaxLength
    {
        set
        {
            if (value < 0) throw new ArgumentOutOfRangeException("value", "Value must be at least 0.");

            maxLength = value;
        }
        get { return maxLength; }
    }

    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        JsonResult json = filterContext.Result as JsonResult;
        if (json != null)
        {
            if (maxLength == 0)
            {
                json.MaxJsonLength = int.MaxValue;
            }
            else
            {
                json.MaxJsonLength = maxLength;
            }
        }
    }
}

Categories

Recent posts