Intro:
Web application, ASP.NET MVC 3, a controller action that accepts an instance of POCO model class with (potentially) large field.
模型类:
public class View
{
[Required]
[RegularExpression(...)]
public object name { get; set; }
public object details { get; set; }
public object content { get; set; } // the problem field
}
Controller action:
[ActionName(...)]
[Authorize(...)]
[HttpPost]
public ActionResult CreateView(View view)
{
if (!ModelState.IsValid) { return /*some ActionResult here*/;}
... //do other stuff, create object in db etc. return valid result
}
Problem:
一个操作应该能够接受大型JSON对象(在一个请求中至少达到httpRuntime maxRequestLength
兆字节,这不是Jest 的).默认情况下,我遇到了一些限制,比如httpRuntime maxRequestLength
等——除了MaxJsonLengh之外,所有限制都已解决——这意味着用于JSON的默认值ProviderFactory无法处理此类对象.
Tried:
背景
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483647"/>
</webServices>
</scripting>
</system.web.extensions>
- 没有帮助.
按照@Darin的回答创建我自己的自定义ValueProviderFactory:
JsonValueProviderFactory throws "request too large"
- 也失败了,因为我不可能使用JSON.净(由于非技术原因).我试图在这里实现正确的反序列化,但显然这有点超出了我的知识范围.我可以在这里将JSON字符串反序列化为
Dictionary<String,Object>
,但这不是我想要的——我想将其反序列化为可爱的POCO对象,并将其用作操作的输入参数.
So, the questions:
- 有谁知道在不实施通用定制值ProviderFactory的情况下解决这个问题的更好方法吗?
- Is there a possibility to specify for what specific controller and action I want to use my custom ValueProviderFactory? If I know the action beforehand than I will be able to deserialize JSON to POCO without much coding in ValueProviderFactory...
- I'm also thinking about implementing a custom ActionFilter for that specific problem, but I think it's a bit ugly.
谁能提出一个好的解决方案?