web.config maxJsonLength issue
I try to send large message json(with images) using HttpClient.PostAsJsonAsync from one side and try get data in Controller using Microsoft.AspNet.Mvc version="5.2.3".
When I send small messages everything is okey.
Move code details:
private async Task<HttpResponseMessage> Method<TRequest>(string url, TRequest request,
IEnumerable<KeyValuePair<string, string>> headers)
{
using (var client = new HttpClient(_httpClientHandlerFactory.CreateHandler()))
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true };
AddHeadersToClient(client, headers);
var response = await client.PostAsJsonAsync(url, request);
...
and on other side:
public class MyController: Controller
{
[HttpPost]
public ActionResult EmailBody(string siteShortName, string templateName, RequestAcceptType acceptType, [DynamicJson] dynamic model)
{
//Some logic
return View(viewPath, model);
}
...
And when sending message I get
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
According article Can I set an unlimited length for maxJsonLength in web.config? I try to solve issue with different approches:
And in all cases I have the same issue.
Its strange to get the max lenght, but are you using base64 images? depending on quantity of images, you can easily get the max Json lenght just like that.
I can suggest a alternative to send large emails with images base64, you can create a view in html and parse with razor engine.
string view = Server.MapPath("~/Views/_YourView.cshtml");
string template = System.IO.File.ReadAllText(view);
body = Razor.Parse(template, youmodel);
链接地址: http://www.djcxy.com/p/42060.html
上一篇: 超过最大请求长度。