System.Web.HttpRequest - ContentLength、TotalBytes 和 InputStream.Length 之间有什么区别?
我正在寻找以下问题的答案:
- 对于任何给定的请求,这三个属性是否始终返回相同的值?
- 它们有副作用吗?
- 它们中的任何一个会阻塞直到 IIS 收到整个请求吗?
- 它们中的任何一个会导致上传的文件完全加载到内存中吗?
我之所以关心这一点,是因为当服务器上处理请求的时间过长时,我会让我的网络应用程序向我发送电子邮件,并且我希望避免针对大型请求(即当用户上传一个或多个大文件时)发送此电子邮件。
I'm looking for answers to questions like these:
- For any given request, do these three properties always return the same value?
- Do any of them have side effects?
- Do any of them block until the entire request is received by IIS?
- Do any of them cause uploaded files to be loaded completely into memory?
I care about this because I'm making my web application email me when a request takes too long to process on the server, and I want to avoid sending this email for large requests, i.e. when the user uploads one or more large files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 MSDN:
ContentLength - 指定客户端发送的内容的长度(以字节为单位)。
TotalBytes - 当前输入流中的字节数。
InputStream.Length - 输入流中的字节长度。
所以最后两个是相同的。以下是 Reflector 关于 ContentLength 属性的说法:
According to MSDN:
ContentLength - specifies the length, in bytes, of content sent by the client.
TotalBytes - the number of bytes in the current input stream.
InputStream.Length - length of bytes in the input stream.
So last two are the same. Here is what Reflector says about ContentLength property: