我们刚刚开始在 Chrome v.29 浏览器上遇到文件下载问题。不会提示用户下载文件。
请看下面的代码:
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();
context.Response.AddHeader("Content-Disposition", "attachment; filename=Test.txt");
context.Response.CacheControl = "private";
context.Response.ContentType = "text/plain";
byte[] data = new byte[Encoding.UTF8.GetByteCount("Test")];
data = Encoding.UTF8.GetBytes("Test");
context.Response.AppendHeader("Content-Length", data.Length.ToString());
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.BinaryWrite(data);
context.Response.Flush();
context.Response.End();
http标头/正文:
HTTP/1.1 200 OK
Date: Thu, 29 Aug 2013 21:47:44 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Content-Disposition: attachment; filename=Test.txt
Content-Length: 4
Cache-Control: private
Content-Type: text/plain
Test
相同的代码适用于除 chrome 之外的所有浏览器!它曾经在 chrome 上工作,直到他们推出了 29 版!!!