添加连接:在 ASP.net 中,保持活动标头不会返回给客户端
简短版本
我正在添加响应标头:
Connection: keep-alive
但它不在响应中。
长版本
我试图添加 标头 到 HttpResponse 在 ASP.net 中:
public void ProcessRequest(HttpContext context)
{
context.Response.CacheControl = "no-cache";
context.Response.AppendHeader("Connection", "keep-alive");
context.Response.AppendHeader("AreTheseWorking", "yes");
context.Response.Flush();
}
当响应返回到客户端(例如 Chrome、Edge、Internet Explorer、Postman)时,Connection
标头丢失:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Transfer-Encoding: chunked
Expires: -1
Server: Microsoft-IIS/10.0
AreTheseWorking: yes
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sat, 26 Feb 2022 16:29:17 GMT
我做错了什么?
还有额外的 Chatter
除了尝试 之外, AppendHeader:
context.Response.AppendHeader("Connection", "keep-alive"); //preferred
我也尝试过AddHeader (其存在“是为了与早期版本的 ASP 兼容”):
context.Response.AddHeader("Connection", "keep-alive"); // legacy
我也尝试过 Headers.Add:
context.Response.Headers.Add("Connection", "keep-alive"); //requires IIS 7 and integrated pipeline
我做错了什么?
奖励: 假设动机对于这个问题
Short Version
I'm adding the response header:
Connection: keep-alive
but it's not in the resposne.
Long Version
I am trying to add a header to an HttpResponse in ASP.net:
public void ProcessRequest(HttpContext context)
{
context.Response.CacheControl = "no-cache";
context.Response.AppendHeader("Connection", "keep-alive");
context.Response.AppendHeader("AreTheseWorking", "yes");
context.Response.Flush();
}
And when the response comes back to the client (e.g. Chrome, Edge, Internet Explorer, Postman), the Connection
header is missing:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Transfer-Encoding: chunked
Expires: -1
Server: Microsoft-IIS/10.0
AreTheseWorking: yes
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sat, 26 Feb 2022 16:29:17 GMT
What am I doing wrong?
Bonus Chatter
In addition to trying AppendHeader:
context.Response.AppendHeader("Connection", "keep-alive"); //preferred
I also tried AddHeader (which exists "for compatibility with earlier versions of ASP"):
context.Response.AddHeader("Connection", "keep-alive"); // legacy
I also tried Headers.Add:
context.Response.Headers.Add("Connection", "keep-alive"); //requires IIS 7 and integrated pipeline
What am i doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,ASP.net 中不允许
keep-alive
。为了允许它,您需要添加一个选项< /a> 到您的
web.config
:web.config:
这对于 服务器发送事件:
By default
keep-alive
is not allowed in ASP.net.In order to allow it, you need to add an option to your
web.config
:web.config:
This is especially important for Server-Send Events: