这与这个问题有关,但在这种情况下,它不是我要返回的东西,而是模型绑定。我正在使用Postmark来处理传入的电子邮件,这些电子邮件会发布到带有JSON 有效负载的页面。
我有一个如下模型和一个接收这个 JSON 有效负载(与 application/json 一起发布)并处理它的操作。
public class EmailModel
{
public IDictionary<string, string> Headers { get; set; }
public string From { get; set; }
public string Cc { get; set; }
public string HtmlBody { get; set; }
public string TextBody { get; set; }
public string ReplyTo { get; set; }
public string Tag { get; set; }
public string To { get; set; }
public string MessageID { get; set; }
public string MailboxHash { get; set; }
public string Subject { get; set; }
public List<Attachment> Attachments { get; set; }
}
public class Attachment
{
public string Content { get; set; }
public int ContentLength { get; set; }
public string ContentType { get; set; }
public string Name { get; set; }
}
这适用于小型附件,但对于超出默认 maxJsonLength 属性的任何内容都会导致反序列化错误。(“使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串的长度超过了 maxJsonLength 属性上设置的值。”)因为我想接受图像附件,这意味着大多数图像都失败了。
我已经尝试更新 web.config,但是根据其他线程,这对 MVC 控制器没有帮助。我想我可能可以做自定义 IModelBinder 中提到的事情,但我正在努力解决如何拦截反序列化。(换句话说,它仍然失败,因为反序列化已经发生了)。
有什么建议么?我敢肯定,我错过了一些愚蠢的东西......