我正在寻找这些问题的答案:
我关心这个,因为当我的Web应用程序在服务器上处理请求的时间过长时,我会给我发电子邮件,我想避免为大请求发送此电子邮件,即当用户上传一个或多个大型请求时文件。
答案 0 :(得分:2)
根据MSDN:
ContentLength - 指定客户端发送的内容的长度(以字节为单位)。
TotalBytes - 当前输入流中的字节数。
InputStream.Length - 输入流中的字节长度。
所以最后两个是一样的。以下是Reflector对ContentLength属性的说法:
public int ContentLength
{
get
{
if ((this._contentLength == -1) && (this._wr != null))
{
string knownRequestHeader = this._wr.GetKnownRequestHeader(11);
if (knownRequestHeader != null)
{
try
{
this._contentLength = int.Parse(knownRequestHeader, CultureInfo.InvariantCulture);
}
catch
{
}
}
else if (this._wr.IsEntireEntityBodyIsPreloaded())
{
byte[] preloadedEntityBody = this._wr.GetPreloadedEntityBody();
if (preloadedEntityBody != null)
{
this._contentLength = preloadedEntityBody.Length;
}
}
}
if (this._contentLength < 0)
{
return 0;
}
return this._contentLength;
}
}