c# - 不调用 Response.Flush 仍然发送连接 : Close in the Response

标签 c# asp.net http connection keep-alive

我的印象是不调用 Response.Flush 将确保不会返回 Connection: Close。那么如何返回 Connection: Keep-Alive?

我正在使用以下代码从 ASP.NET 返回一个文件。

Response.ContentType = type;
Response.AppendHeader("Content-Length", bytes.Length.ToString());
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
Response.Cache.SetExpires(expiryDate);
Response.Cache.SetLastModifiedFromFileDependencies();
Response.Cache.SetETag(etag);
Response.OutputStream.Write(bytes, 0, bytes.Length);

生成的响应是:

HTTP/1.1 200 OK
Server: ASP.NET Development Server/9.0.0.0
Date: Fri, 01 Oct 2010 12:50:17 GMT
X-AspNet-Version: 2.0.50727
X-AspNetMvc-Version: 2.0
Content-Length: 34808
Cache-Control: public, must-revalidate
Expires: Fri, 01 Oct 2010 12:51:17 GMT
Last-Modified: Wed, 22 Sep 2010 16:00:33 GMT
ETag: "302E7A7D0D9DA91BABB53F6B6FE0B005"
Content-Type: image/gif
Connection: Close

最佳答案

我不确定您是否可以向开发服务器发送连接:Keep-Alive。

您可以在 IIS7 中进行设置,方法是浏览到 IIS 管理器中的“HTTP 响应 header ”部分,然后单击右侧的“设置通用 header ...”操作。

关于c# - 不调用 Response.Flush 仍然发送连接 : Close in the Response,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3839368/

相关文章:

c# - 在 VS 可扩展性演练中,Guid 应包含 32 位数字和 4 个破折号 (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)

c# - 在 IE 11 中,在导航到 Angular 应用程序中的另一个页面时,favicon 消失了

c# - 专注于文本框

asp.net - 防止在文本框中输入非 ascii 字符

验证码的 HTTP 状态代码

google-chrome - 了解 Chrome 网络日志 "Stalled"状态

c# - 使用 Moq 测试抽象类

c# - 在 TCP 套接字数据发送 C# 之间获取恒定延迟

c# - 将图像切成小块

php 替代爆炸