Problem with maxJsonLength in web.config

I am trying to send a large json message (with images) using HttpClient.PostAsJsonAsync on the one hand and try to get the data in the controller using Microsoft.AspNet.Mvc version = "5.2.3".

When I send small messages, all this is okey.

Move code information:

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 the other hand:

   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 a message I get

Error during serialization or deserialization using JSON JavaScriptSerializer. The string is longer than the value specified for the maxJsonLength property.

According to the article Can I set unlimited length for maxJsonLength in web.config? I am trying to solve a problem with various statements:

  • added to web.config section
  • - Global.asax

.

+4
1

, , base64? , Json .

base64, html .

string view = Server.MapPath("~/Views/_YourView.cshtml");
string template = System.IO.File.ReadAllText(view);
body = Razor.Parse(template, youmodel);
0

All Articles