본문 바로가기

Programming/Asp.Net MVC

How to increase max json length for ASP.Net MVC

Error

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.


파일 업로드를 angularJs의 base64 uploader를 이용했더니, 파일 용량이 크거나, 한 번에 전송하는 파일 개수가 많아지는 경우 위와 같은 오류 메시지를 받았습니다.

ASP.Net MVC의 Default max json length는 100K이며, 이를 넘기는 경우 요청이 MVC API, Action 께 도달하지 않고, 500 http status code가 반환됩니다.

(즉, 요청이 controller에 도달하지 않으므로, 디버깅도 불가능...)


이를 해결하기 위해서는 별도의 ValueProviderFactory를 구현한 뒤, Global.asax의 Application_Start 부분에 다음의 코드를 추가해야 합니다.


Application_Start()


CustomJsonValueProviderFactory


References

http://stackoverflow.com/questions/3853767/maximum-request-length-exceeded

http://forums.asp.net/t/1751116.aspx?How+to+increase+maxJsonLength+for+JSON+POST+in+MVC3



'Programming > Asp.Net MVC' 카테고리의 다른 글

Automatically convert viewmodel properties to camel case.  (0) 2015.07.29
Web cache  (0) 2015.01.28
ASP.NET vNext  (0) 2014.10.06
Dynamic resource file handling  (0) 2014.07.22
ActionFilter  (0) 2014.07.22