Reputation: 3147
I'm migrating an existing MVC5 json webservice to AspNet Core RC2 running on full framework (NET 4.6.1).
Every controller inherits from _BaseController:
public class _BaseController : Controller
{
public IActionResult Success(object data) { return Json({ IsSuccess = true, Data = data }); }
public IActionResult Error(string message) { return Json({ IsSuccess = false, Message = message }); }
}
This is a sample controller:
public class SampleController : _BaseController
{
public IActionResult Something() { return Success(new { FirstItem = "First", SecondItem = "Second", ThirdItem = 1 }); }
}
On RC1 this worked fine. Response was just fine.
After updating to RC2, the JSON response now contains some strange/invalid chars.
From Fiddler, this is the original (valid) response:
{"isSuccess":true,"data":{"firstItem":"first","secondItem":"second","thirdItem":1}}
But RC2 delivers an invalid response like this (full raw response from Fiddler which is the same as received by .NET winforms client):
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
Server: Kestrel
X-Powered-By: ASP.NET
Date: Tue, 28 Jun 2016 20:38:55 GMT
3de
{"sucesso":true,"dados":{"codigo":1,"dataUltimaAtualizacao":"2016-06-27T00:00:00","horaUltimaAtualizacao":"17:18:06.8099844","offsetHoraUltimaAtualizacao":-180,"cnpj":"23303829000169","razaoSocial":"NACIONAL SOFT LTDA","nomeFantasia":"NACIONAL SOFT","tipoEstabelecimento":"MATRIZ","inicioAtividade":"1987-05-13T00:00:00","atividadePrimaria":"62.03-1-00 - Desenvolvimento e licenciamento de programas de computador não-customizáveis","atividadesSecundarias":"62.02-3-00 - Desenvolvimento e licenciamento de programas de computador customizáveis","naturezaJuridica":"206-2 - SOCIEDADE EMPRESARIA LIMITADA","logradouro":"R HORTENCIA","numero":"591","complemento":"CONJUNTO 01","bairro":"ESPLANADA","municipio":"BELO HORIZONTE","uf":"MG","cep":"30280250","enderecoEletronico":"","telefone":"","enteFederativoResponsavel":"*****","situacaoCadastral":"ATIVA","dataSituacaoCadastral":"2005-11-03T00:00:00","motivoSituacaoCadastral":"","situacaoEspecial":"********","dataSituacaoEspecial":null}}
0
This is driving me crazy here. Does anyone have any idea if it's related to integration between Kestrel and IIS? Any clue at all?
Upvotes: 2
Views: 2164
Reputation: 3147
Yeah, it's all about chuncked response as CodeCaster commented.
I'll try and fix the client as well but this previous question has a fix for this.
So, if anyone runs into this again, just add a reference to Microsoft.AspNetCore.Buffering
on package.json
and this line on Startup.cs
:
app.UseResponseBuffering();
Upvotes: 1