与Response.TransmitFile,到Response.End和IE浏览器问题 [英] Problems with Response.TransmitFile, Response.End and IE
问题描述
我开发一个ASP.NET应用程序,它在一个点一个文件发送给用户,使用Response.TransmitFile。
I am developing an ASP.NET app which at one point sends a file to the user, using Response.TransmitFile.
它工作正常,我的开发机器上,当我将它部署到测试服务器仍然工作在其中的两个;虽然在服务器(W2K3)它只能在Firefox中,当我尝试在IE7我得到一个错误,如其中的Internet Explorer可以(服务器名)无法打开文件sendfile.aspx。
It works fine on my dev machine, and when I deploy it to the test servers it still works on two of them; in one of the servers though (W2K3) it only works on Firefox, when I try it on IE7 I get an error like "Internet Explorer cannot open file sendfile.aspx on (server name)".
我创建了一个小型内嵌aspx页面来摄制的问题,那就是:
I've created a small inline aspx page to repro the problem, here it is:
<%@ Page Language="C#" %>
<html><head>
<script language="CS" runat="server">
void Page_Load(object sender, System.EventArgs e)
{
string filePath = @"C:\temp\export.zip";
Response.ClearHeaders();
Response.ContentType = "application/zip";
Response.Clear();
Response.AppendHeader("Content-disposition", "attachment; filename=export.zip");
Response.TransmitFile(filePath);
Response.End();
}
</script>
</head></html>
我已经尝试不同的事情,我发现,如果我注释掉到Response.End
行(但据我所知这条线应该有,根据至少再工作每一个样品code我发现网络上)
I've tried different things and I noticed that it works again if I comment out the Response.End
line (but AFAIK this line should be there, at least according to every sample code I find around the web)
我注意到另一个问题,这可能会或可能不相关的是,它还会如果我删除&LT失败; HTML&GT中,&lt; HEAD&GT;
和结束标记
Another issue I noticed which may or may not be related is that it will also fail if I remove the <html>, <head>
and its closing tags.
我一直在抓我的头在这个现在一段时间,没有任何人有一个线索如何得到这个工作?
I've been scratching my head over this for a while now, does anyone have a clue how to get this to work?
推荐答案
不要使用到Response.End();
Don't use Response.End();
尝试
Response.TransmitFile(filePath);
Response.End();
其实,.NET 2.0之后,你应该使用
in fact, after .NET 2.0, you should use
Response.TransmitFile(filePath);
context.HttpApplication.CompleteRequest();
这篇关于与Response.TransmitFile,到Response.End和IE浏览器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!