我正在ASP .Net C#中动态生成CSV文件,并将其直接写入响应。
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-element的方式(http://msdn.microsoft.com/en-us/library/e1f13641的.aspx)。
谢谢!