我在 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-property 设置为 httpRuntime-element (http://msdn.microsoft.com/en-us/library/e1f13641.aspx) .
谢谢!