2016-04-19 12 views
4

HttpClient.PostAsJsonAsyncを使用して大きなメッセージjson(画像付き)を片面から送信し、Microsoft.AspNet.Mvc version = "5.2.3"を使用してControllerでデータを取得しようとしました。web.config maxJsonLength issue

小さなメッセージを送信すると、すべてがokeyになります。

移動コードの詳細:

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); 
      ... 

と反対側に:

public class MyController: Controller 
    { 
    [HttpPost] 
    public ActionResult EmailBody(string siteShortName, string templateName, RequestAcceptType acceptType, [DynamicJson] dynamic model) 
    { 
     //Some logic 
     return View(viewPath, model); 
    } 
... 

そして、私はJSON JavaScriptSerializerを使用して直列化または直列化復元時に

エラーを取得するメッセージを送信します。文字列の長さがmaxJsonLengthプロパティで設定された値を超えています。 web.configファイルsection

  • に追加

  • すべてのケースで私はame issue。

    答えて

    0

    最大長を取得するのは奇妙ですが、base64イメージを使用していますか? 画像の数に応じて、あなたは簡単にそのような最大のJsonの長さを得ることができます。

    イメージbase64の大きなメールを送信する代わりに、HTMLでビューを作成して、剃刀エンジンで解析することもできます。

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