IIS7下载文件长度 [英] IIS7 downloading file length

查看:100
本文介绍了IIS7下载文件长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面code文件下载:

I've following code for file download:

        FileInfo fileInfo = new FileInfo(filePath);

        context.Response.Clear();
        context.Response.ContentType = "application/octet-stream";
        context.Response.AddHeader("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(filePath));
        context.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
        context.Response.WriteFile(filePath);
        context.Response.End();

当我在我的本地IIS6运行它,它工作正常。 Web浏览器(IE8的,火狐3.5.2测试,歌剧10)显示之前,我开始下载该文件的文件长度。

When I run it on my local IIS6 it works fine. Web browser (tested on IE8, Firefox 3.5.2, Opera 10) shows file length before I start download the file.

当我运行在远程IIS7这个code,网页浏览器不显示文件长度。文件长度是未知的。

When I run this code on remote IIS7, web browser doesn't shows file length. File length is unknown.

为什么我没有得到文件的长度时,该code IIS7下运行?

Why I don't get file length when this code runs under IIS7?

推荐答案

使用提琴手检查什么实际发送。我的猜测是你得到分块编码作为缓冲的结果被设置为false IIS7服务器上。

Use Fiddler to check what is actually sent. My guess is you are getting chunked encoding as a result of buffering being set to false on the IIS7 server.

BTW,跌落到Response.End调用其相当创伤的事是不必要的(为此事所以是调用清除)。

BTW, drop the Response.End call its quite a traumatic thing to do and is unnecessary (for that matter so is the call to Clear).

修改

严格按照分块编码(这是可取的您的方案)的Content-Length头应该不会是present(见的 RFC2616 4.4节)。这在我看来,IIS7需要独自去执行这一点。其实我有一个经典-ASP方案,其中IIS7时COM code尝试添加一个Content-Length头时,缓冲是关闭抛出一个错误。

Strictly speaking when streaming content with chunked encoding (which is desirable in your scenario) the Content-Length header ought not be present (see RFC2616 Section 4.4.) It seems to me that IIS7 takes it upon itself to enforce this. In fact I've had a Classic-ASP scenario in which IIS7 throws an error when COM code tries to add a Content-Length header when buffering is off.

这是真的很烦,因为尽管在象牙塔委员会想什么,这头给最终用户信息的一个非常有用的棋子。

This is really annoying because despite what the committee in the ivory towers would like, this header give the end user a very useful piece of info.

这篇关于IIS7下载文件长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆