Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.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/1/asp.net/36.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
Http响应文件下载在Internet explorer和chrome(C#,Asp.net)中不起作用_C#_Asp.net_Internet Explorer_Google Chrome - Fatal编程技术网

Http响应文件下载在Internet explorer和chrome(C#,Asp.net)中不起作用

Http响应文件下载在Internet explorer和chrome(C#,Asp.net)中不起作用,c#,asp.net,internet-explorer,google-chrome,C#,Asp.net,Internet Explorer,Google Chrome,我在C#asp.net中编写了一个文件下载方法,将文件从服务器下载到客户机 我编写了以下代码: Response.ContentType = ReturnExtension(System.IO.Path.GetExtension(file.Name)); Response.AppendHeader("Content-Disposition", "attachment; filename=" + file.Name);

我在C#asp.net中编写了一个文件下载方法,将文件从服务器下载到客户机

我编写了以下代码:

Response.ContentType = ReturnExtension(System.IO.Path.GetExtension(file.Name));

                    Response.AppendHeader("Content-Disposition", "attachment; filename=" + file.Name);

                    Response.TransmitFile(strRequest);

                    Response.End();

这在Firefox和Chrome中可以正常工作,但在IE中不行。

我在某些版本的IE中遇到了类似的问题,必须设置缓存控制头才能使下载正常工作:

response.Cache.SetCacheability(HttpCacheability.Private);

尝试在代码上方放置一个
响应.Clear()

当您说它不下载时,它会在浏览器窗口中打开吗?什么也不做?您能确认ReturnExtension方法返回mime类型吗?这个名字听起来不像,但我想我应该检查一下。。。你的文件名也有空格吗?或者其他可能会混淆该头的内容?文件名中的空格不应该造成问题,但您必须具有适当的ContentType,而文件扩展名不是。我的ReturnExtension方法检查文件扩展名,并根据扩展名返回mime类型,如果文件的扩展名为.bmp,它将返回字符串“image/bmp”。当我点击下载按钮时,不会出现保存或打开对话框,但在firefox和chrome中一切正常,但在internet explorer中什么也没有发生,我不知道这个问题的原因,请有人给我任何提示,谢谢。