I have a web api which returns IActionResult
.
I return FileContentResult
from this api like this
return new FileContentResult(model.Content, ContentType)
{
EnableRangeProcessing = true
};
I have a requirement in which I now want to control StatusCode
myself, rather than FileContentResult
decide itself.
I don't find any way to do this.
Basically I want to return my own designed HttpResponseMessage
in which I can set headers and other stuff myself.
But I don't find any way to do this for IActionResult
type.
The only thing that I thought could work is to use ResponseMessageResult
something like this
var content = new ByteArrayContent(bytesWithValidationData);
var response = new HttpResponseMessage();
response.Content = content;
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response.StatusCode = HttpStatusCode.PartialContent;
response.Content.Headers.ContentRange = new ContentRangeHeaderValue(from, to);
return new ResponseMessageResult(response);
But its response is not same as HttpResponse, it just returns json result with HttpResponseMessage
object details but does not actually return Http response considering content type etc. where I can download the file.
It gives result like this
Is there any way I can return my designed file result type http response?