gpt4 book ai didi

c# - HttpContext.Current.Response.Filter : Response filter is not valid

转载 作者:太空狗 更新时间:2023-10-29 22:26:31 25 4
gpt4 key购买 nike

忙于将一些遗留代码写入 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);

但是当代码到达:

// Clear any settings (such as GZip)
HttpContext.Current.Response.Filter = null;//exception occurs here

它抛出一个 HttpException

Response filter is not valid.

所以我的问题是:

1) 如何将过滤器设置为空过滤器或默认过滤器?

2) 有必要吗?

预先感谢您的帮助

最佳答案

检查这个post .尽管它谈论的是 ASp.Net 3.5,但我试过了并且它有效。我刚刚读取了过滤器 var filter = Response.Filter,然后为其分配了 null Response.Filter = null

关于c# - HttpContext.Current.Response.Filter : Response filter is not valid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22449603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com