I want to write the following code for the asp.net core 8 environment.
Response.Buffer = true;
Response.AppendHeader("Content-Disposition", "filename=license.txt");
Response.ContentType = "application/text";
Response.Output.Write(data);
Response.Flush();
Response.End();
I managed to add header by the following line.
HttpContext.Response.Headers["Content-Disposition"] = "filename=license.txt";
In your handler method, you only need the following to replace what you posted:
return File(Encoding.UTF8.GetBytes(data), "application/text", "licence.txt");
You might need to add a using
directive for System.Text
:
using System.Text;