我在一个旧的ASP.NET webforms应用程序中使用了此代码,
MemoryStream
并将其作为显示PDF作为响应的响应传递。我现在正在使用一个ASP.NET MVC应用程序,并希望做同样的事情,但是我应该如何开始显示
内存流
以PDF格式使用MVC?
以下是我的ASP.NET WebForms代码:
private void ShowPDF(MemoryStream ms)
{
try
{
//get byte array of pdf in memory
byte[] fileArray = ms.ToArray();
//send file to the user
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
Page.Response.Buffer = true;
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.Charset = string.Empty;
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", fileArray.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment;filename=TID.pdf;");
Response.BinaryWrite(fileArray);
Response.Flush();
Response.Close();
}
catch
{
// and boom goes the dynamite...
}
}