public IActionResult DownloadFile(int requestId) { var data = _repository.GetScanRequestById(requestId); if (data.ScanNmap.FirstOrDefault() == null) { string responseMssg = "Bad Url"; Response.Body.Write(Encoding.ASCII.GetBytes(responseMssg)); return(BadRequest()); } var htmlContent = _xmlConverter.TransformXMLToHTML(data.ScanNmap.FirstOrDefault()?.ScanResult); htmlContent = _htmlHelper.AddDirbResults(htmlContent, data); htmlContent = _htmlHelper.AddVirusTotalResults(htmlContent, data); htmlContent = _htmlHelper.AddHashCheckResults(htmlContent, data); byte[] buff = Encoding.ASCII.GetBytes(htmlContent); // get the file and convert it into a bytearray return(new FileContentResult(buff, new MediaTypeHeaderValue("application/octet")) { FileDownloadName = "result.html" }); }