本文整理汇总了C#中IResponse.AddHttpRangeResponseHeaders方法的典型用法代码示例。如果您正苦于以下问题:C# IResponse.AddHttpRangeResponseHeaders方法的具体用法?C# IResponse.AddHttpRangeResponseHeaders怎么用?C# IResponse.AddHttpRangeResponseHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IResponse
的用法示例。
在下文中一共展示了IResponse.AddHttpRangeResponseHeaders方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WritePartialTo
public void WritePartialTo(IResponse response)
{
var contentLength = GetContentLength().GetValueOrDefault(int.MaxValue); //Safe as guarded by IsPartialRequest
var rangeHeader = RequestContext.GetHeader(HttpHeaders.Range);
long rangeStart, rangeEnd;
rangeHeader.ExtractHttpRanges(contentLength, out rangeStart, out rangeEnd);
response.AddHttpRangeResponseHeaders(rangeStart, rangeEnd, contentLength);
var outputStream = response.OutputStream;
if (FileInfo != null)
{
using (var fs = FileInfo.OpenRead())
{
fs.WritePartialTo(outputStream, rangeStart, rangeEnd);
}
}
else if (ResponseStream != null)
{
ResponseStream.WritePartialTo(outputStream, rangeStart, rangeEnd);
DisposeStream();
}
else if (ResponseText != null)
{
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(ResponseText)))
{
ms.WritePartialTo(outputStream, rangeStart, rangeEnd);
}
}
else
throw new InvalidOperationException("Neither file, stream nor text were set when attempting to write to the Response Stream.");
}