是否可以通过IIS从ASP.NET Core强制返回Connection标头? [英] Is it possible to force return the Connection header from ASP.NET Core through IIS?

查看:157
本文介绍了是否可以通过IIS从ASP.NET Core强制返回Connection标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:这类似于

Note: This is similar to this question but is about IIS, not Azure App Service on Linux.

我有一个用于上传大型文件的API端点.如果验证失败,文件名无效等,则不应上传文件.我们甚至接受校验和,如果文件已经存在,则跳过上传.

I have an API endpoint for uploading large files. The file should not be uploaded if authentication fails, if the filename is invalid, etc. We even accept a checksum and skip upload if the file already exists.

不幸的是,无论我在用户代码中做什么,Kestrel总是耗尽整个请求正文(请参见此问题以获取详细信息).换句话说,用户必须上传"消息.即使在我的代码未读取响应主体并返回早期错误响应的情况下,也无法获得响应之前的整个文件.在该问题中,我收到一条提示,我可以返回Connection: close标头来避免这种情况.不幸的是,虽然在本地调试时在响应中收到标头,但在通过IIS在生产环境中运行时却没有收到标头.换句话说,如果ASP.NET Core响应中存在该标头,则IIS似乎会删除该标头.

Unfortunately, Kestrel always drains the entire request body no matter what I do in user code (see this issue for details). In other words, the user has to "upload" the whole file before getting the response, even if my code does not read the response body and returns an early error response. In that issue I received a tip that I could return a Connection: close header to avoid that. Unfortunately, while I receive the header in the response when debugging locally, I do not receive it when running in production through IIS. In other words, IIS seems to remove that header if it's present in the ASP.NET Core response.

是否可以通过IIS强制返回Connection: close标头?

Is there any way to force return a Connection: close header through IIS?

推荐答案

我认为您可以尝试为asp.net核心应用程序禁用allowKeepAlive.

I think you could try to disable allowKeepAlive for your asp.net core application.

<system.webServer>
    <httpProtocol allowKeepAlive="false" />
</system.webServer>

这篇关于是否可以通过IIS从ASP.NET Core强制返回Connection标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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