开发者

Http response file download not working in Internet explorer and chrome (C#, Asp.net)

开发者 https://www.devze.com 2023-03-26 16:44 出处:网络
I write a file download method to download file from server to client machine in C# asp.net I wrote the following code:

I write a file download method to download file from server to client machine in C# asp.net

I wrote the following code:

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

                    Response.AppendHeader("Content-Disposition", "attachment;开发者_开发知识库 filename=" + file.Name);

                    Response.TransmitFile(strRequest);

                    Response.End();

This will work fine in Firefox and Chrome, but not in IE.


I was facing similar issue in some versions of IE and had to set Cache-Control header to make the download working properly:

response.Cache.SetCacheability(HttpCacheability.Private);


try to put a Response.Clear() on top of your code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号