IIS7 - 在 ASP 中指定内容长度标头会导致“连接重置"错误 [英] IIS7 - Specifying content-length header in ASP causes "connection reset" error

查看:20
本文介绍了IIS7 - 在 ASP 中指定内容长度标头会导致“连接重置"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一系列网站从现有的 IIS5 服务器迁移到全新的 IIS7 Web 服务器.其中一个页面从数据库中的 blob 中提取数据文件并将其提供给最终用户:

I'm migrating a series of websites from an existing IIS5 server to a brand new IIS7 web server. One of the pages pulls a data file from a blob in the database and serves it to the end user:

Response.ContentType = rs("contentType")
Response.AddHeader "Content-Disposition", "attachment;filename=" & Trim(rs("docName"))&rs("suffix")' let the browser know the file name
Response.AddHeader "Content-Length", cstr(rs("docsize"))' let the browser know the file size

在新的 IIS7 安装中对此进行测试,我在 Internet Explorer 和 Firefox 中都收到连接重置"错误.如果移除 Content-Length 标头,则文档会正确提供(但用户不会获得有用的进度条).

Testing this in the new IIS7 install, I get a "Connection Reset" error in both Internet Explorer and Firefox. The document is served up correctly if the Content-Length header is removed (but then the user won't get a useful progress bar).

关于如何纠正此问题的任何想法;无论是服务器配置选项还是通过代码?

Any ideas on how to correct this; whether it be a server configuration option or via code?

编辑 1: 做了更多的试验和错误.如果启用缓冲"和启用分块编码"都为 false,则请求将成功.如果启用其中一个,则会发生错误.

Edit 1: Did a bit more trial and error. The requests will succeed if both "Enable Buffering" and "Enable Chunked Encoding" are false. If either one is enabled the error occurs.

编辑 2: 更多的试错测试;事实证明,文本文件可以很好地与脚本配合使用;只有二​​进制文件(图像、pdf 等)会失败.否则仍然完全一无所知.

Edit 2: More trial and error testing; turns out that text files will work fine with the script; only binary files (images, pdfs, etc.) will fail. Still completely clueless otherwise.

推荐答案

正如在其他地方已经提到的:http://en.wikipedia.org/wiki/Chunked_transfer_encoding

As already mentioned somewhere else: http://en.wikipedia.org/wiki/Chunked_transfer_encoding

它使用 Transfer-Encoding HTTP 响应标头代替协议需要的 Content-Length 标头.因为没有使用 Content-Length 标头,所以服务器在开始向客户端(通常是 Web 浏览器)发送响应之前不需要知道内容的长度.Web 服务器可以在知道内容的总大小之前就开始使用动态生成的内容传输响应.

It uses the Transfer-Encoding HTTP response header in place of the Content-Length header, which the protocol would otherwise require. Because the Content-Length header is not used, the server does not need to know the length of the content before it starts transmitting a response to the client (usually a web browser). Web servers can begin transmitting responses with dynamically-generated content before knowing the total size of that content.

在 IIS7 中这是默认启用的:http://technet.microsoft.com/en-us/library/cc730855(v=ws.10).aspx

In IIS7 this is enabled by default: http://technet.microsoft.com/en-us/library/cc730855(v=ws.10).aspx

为万维网启用 HTTP 1.1 分块传输编码发布服务,使用如下语法:

To enable HTTP 1.1 chunked transfer encoding for the World Wide Web publishing service, use the following syntax:

appcmd 设置配置/section:asp/enableChunkedEncoding:True|False

appcmd set config /section:asp /enableChunkedEncoding:True|False

True 启用 HTTP 1.1 分块传输编码,而 False 禁用HTTP 1.1 分块传输编码.默认值为 True.

True enables HTTP 1.1 chunked transfer encoding whereas False disables HTTP 1.1 chunked transfer encoding. The default value is True.

我们遇到了同样的问题,我们的解决方案:删除 AddHeader "Content-Length"

We had the same problem, our solution: remove AddHeader "Content-Length"

这篇关于IIS7 - 在 ASP 中指定内容长度标头会导致“连接重置"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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