How to properly stream response in ASP.NET Core? There is a controller like this (UPDATED CODE):
[HttpGet(\"test\")]
public async Task GetT
It is possible to return null
or EmptyResult()
(which are equivalent), even when previously writing to Response.Body
. It may be useful if the method returns ActionResult
to be able to use all the other results aswell (e.g. BadQuery()
) easily.
[HttpGet("test")]
public ActionResult Test()
{
Response.StatusCode = 200;
Response.ContentType = "text/plain";
using (var sw = new StreamWriter(Response.Body))
{
sw.Write("something");
}
return null;
}