我有一个 HttpHandler
,它返回一个大块(~400k 行)的 XML 数据。由于某些原因,在传输过程中数据被损坏了。以下是一个简单的测试用例:
public class SimpleTestCase : HttpHandlerBase
{
public override bool IsReusable
{
get { return false; }
}
protected override void HandleRequest(HttpContext context)
{
context.Response.ContentType = "application/xml";
context.Response.Write("<?xml version=\"1.0\"?>" + Environment.NewLine);
for(var i = 0; i < 400010; i++)
{
context.Response.Write("<amount>5</amount>" + Environment.NewLine);
}
}
}
当我查看结果时,我发现大约有400,010个实例中大约有60个这样写:
60 of the 400,010
。 <amount>5amount>
注意到关闭标签的开头部分(
</
)缺失了。为什么Response
流会被破坏?更重要的是,我该如何防止它发生?更新:如果有关联的话,使用的是Visual Studio 2013、IIS Express、.NET 4.5。