我需要從服務器下載文件。它的代碼如下所示:在mozilla中顯示打開/下載文件選項
public void ProcessRequest(HttpContext context)
{
string fileName = context.Request.QueryString["fileName"];
string filePath = HostingEnvironment.ApplicationPhysicalPath + "/TempFolder/" + fileName;
if (File.Exists(filePath))
{
context.Response.ContentType = "application/octet-stream";
context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
{
int _READ_LEN = 3000;
int bLength = _READ_LEN;
BinaryReader bReader = new BinaryReader(fileStream);
if (bReader.BaseStream.Length < _READ_LEN)
bLength = (int)bReader.BaseStream.Length;
while (bReader.BaseStream.Position != bReader.BaseStream.Length)
{
context.Response.BinaryWrite(bReader.ReadBytes(bLength));
if ((bReader.BaseStream.Length - bReader.BaseStream.Position) < _READ_LEN)
bLength = (int)(bReader.BaseStream.Length - bReader.BaseStream.Position);
}
}
context.Response.Flush();
File.Delete(filePath);
}
}
當我嘗試下載文件在Mozilla,它會自動下載文件,而不要求爲開/下載文件,而它顯示了該選項,在IE工作時。 我需要這個選項才能在Mozilla中顯示。 我試圖搜索的東西,但找不到任何有用的東西。 任何人都可以請建議一個解決方案?