我有一个webforms应用程序,它在ashx文件中有一个下载处理程序,该文件被重定向到web.config中的urlMapping。这项工作正常,但我还想支持继续下载 - 它使用Range请求标头。但是,虽然发送了Range标头,但它在服务器上不可见。
我的测试请求如下所示:
GET http://localhost:81/Downloads/MyFile.zip HTTP/1.1
Host: localhost:81
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
Accept-Language: en-US,en;q=0.8,nl;q=0.6
Range: bytes=3-
然而,当我在服务器上尝试读取Range标头时,我什么都没得到。以下代码:
var request = HttpContext.Current.Request;
Debug.WriteLine("/" + request.HttpMethod + " " + request.RawUrl);
foreach (var key in headers.AllKeys)
{
Debug.WriteLine(key + ": " + context.Request.Headers[key]);
}
给我的输出是:
/GET /Downloads/MyFile.zip
Cache-Control: max-age=0
Connection: keep-alive
Content-Length: 0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.8,nl;q=0.6
Host: localhost:81
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
不知何故,Range标题消失了,并且添加了“Content-Length:0”标题。
我的问题是:为什么要删除范围标题,我该如何取回它?