繁忙的一些遗留代码写入csv/xls:
// Set up response
string filename = "ErrorControlExport";
string attachment = "attachment; filename=" + filename + "_" + DateTime.UtcNow.ToFileTime() + "." + extension;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.ContentType = contentType;
HttpContext.Current.Response.AddHeader("Pragma", "public");
// Clear any settings (such as GZip)
HttpContext.Current.Response.Filter = null;//exception occurs here
// Add BOM to force recognition of UTF-8
byte[] bom = new byte[] { 0xef, 0xbb, 0xbf };
HttpContext.Current.Response.BinaryWrite(bom);
Run Code Online (Sandbox Code Playgroud)
但是当代码到达时:
// Clear any settings (such as GZip)
HttpContext.Current.Response.Filter = null;//exception occurs here
Run Code Online (Sandbox Code Playgroud)
它抛出一个HttpException的
响应过滤器无效.
所以我的问题是:
1)如何将过滤器设置为空或默认过滤器?
2)甚至是必要的吗?
在此先感谢您的帮助