2012-03-20 548 views
4

我在ASP.Net C#中生成一个CSV文件,并直接写入响应。写入httpResponse时,响应是否有大小限制?

private void ExportToResponse(string textCsv, string fileName) 
    { 
     HttpContext.Current.Response.Clear(); 
     HttpContext.Current.Response.ContentType = "text/csv"; 
     HttpContext.Current.Response.ContentEncoding = Encoding.Unicode; 
     HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + ".csv"); 
     HttpContext.Current.Response.Write(textCsv); 
     HttpContext.Current.Response.End(); 
    } 

,在大多数情况下,这工作得很好,但在某些情况下,我得到一个错误(“本网站无法显示在Internet Explorer”)。我怀疑这是因为这个文件越来越大。在这种情况下,如何扩展响应长度的限制?

我希望我可以在web.config文件中做到这一点,类似于你将mexRequestLength属性设置为httpRuntime元素(http://msdn.microsoft.com/en-us/library/ e1f13641.aspx)。

谢谢!

+0

你托管在IIS网站下面的Microsoft知识库文章,如果是哪个版本? – 2012-03-20 11:46:17

+0

是的,我愿意,版本6.0 – linnkb 2012-03-20 11:52:16

+0

它最好发送它的部分,而不是全部在一个。同时禁用缓冲区,并使用处理程序发送它,而不是从页面内部发送,因为会话将锁定其他用户,并且您将有超时。 – Aristos 2012-03-20 12:05:32

回答

相关问题