In the Aspnet5 RC1 web application update1 trying to do the same thing as Response.BinaryWrite, loading the file in the old AspNet application. The user should receive a pop-up save dialog on the client side.
when the following code is used, a pop-up prompt appears on the client side to save the file.
public void Configure(IApplicationBuilder app)
{
app.Run(async (objContext) =>
{
var cd = new System.Net.Mime.ContentDisposition {
FileName = "test.rar", Inline = false };
objContext.Response.Headers.Add("Content-Disposition", cd.ToString());
byte[] arr = System.IO.File.ReadAllBytes("G:\\test.rar");
await objContext.Response.Body.WriteAsync(arr, 0, arr.Length);
});
}
But when the same code is used inside the Controller action, app.Run is commented out, the preservation of the pop-up window is not displayed, the content is simply displayed as text.
[Route("[controller]")]
public class SampleController : Controller
{
[HttpPost("DownloadFile")]
public void DownloadFile(string strData)
{
var cd = new System.Net.Mime.ContentDisposition {
FileName = "test.rar", Inline = false };
Response.Headers.Add("Content-Disposition", cd.ToString());
byte[] arr = System.IO.File.ReadAllBytes("G:\\test.rar");
Response.Body.WriteAsync(arr, 0, arr.Length);
The need is that the control flow must go to the controller, execute some logic, and then send byte [] response content to the client side, the user needs to save the file. No cshtml, just html with jquery ajax call.