Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#文件下载返回损坏的文件-传输文件_C#_File_Download_Response.transmitfile - Fatal编程技术网

C#文件下载返回损坏的文件-传输文件

C#文件下载返回损坏的文件-传输文件,c#,file,download,response.transmitfile,C#,File,Download,Response.transmitfile,在我们的服务器上,我们使用虚拟目录在同一个域下托管了10多个网站。现在,其中文件下载功能在除2外的所有网站上都能正常工作。我已经用下面的函数检查了所有内容,但仍然不起作用 HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.ContentType = "application/octet-stream"; HttpContex

在我们的服务器上,我们使用虚拟目录在同一个域下托管了10多个网站。现在,其中文件下载功能在除2外的所有网站上都能正常工作。我已经用下面的函数检查了所有内容,但仍然不起作用

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlPathEncode(strFileName));
HttpContext.Current.Response.TransmitFile(fileDirectory + @"\" + fileName);
HttpContext.Current.Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
请注意,我还尝试为内容长度设置代码,清除响应缓存,但没有任何效果。事实上,我也比较了工作和非工作网页的请求头,但它们也是一样的。请注意,当我在ashx页面中使用相同的代码时,文件下载工作正常!我99.99%确信这一定是编码以外的问题,因为我没有发现其他网站有任何问题

如果有人能专注于此,我们将不胜感激!否则,我将别无选择地采用其他解决方案


提前谢谢

你还没有说到底出了什么问题。。。“损坏的文件”可能意味着什么。哦,我的错。当我下载文件时上传文件后,下载的文件并没有被打开。这就是问题所在。您对原始文件和损坏文件之间的差异进行了哪些诊断?它们大小一样吗?有什么不同的模式吗?你确定你的服务器上不仅仅有一个损坏的文件吗?是的,最初我下载时得到了文件大小的差异,但当我使用内容长度时,它也不起作用。我已经检查了正在使用fiddler下载文件的工作和非工作网站页面的请求标题。我不知道其他的技巧。如果你有更好的主意,请告诉我。明白了!!最后我解决了这个问题。我很久以前就在项目中实现了压缩模块,但并没有意识到我必须检查请求的text/xml内容类型。我一拆下它,一切就开始工作了。