在 Asp.NET 1.1 中无法更改自定义标头。
我只使用反射解决问题。
// first of all we need get type ArrayList with custom headers:
Type responseType = Response.GetType();
ArrayList fieldCustomHeaders = ArrayList)responseType.InvokeMember("_customHeaders",BindingFlags.GetField|BindingFlags.Instance|BindingFlags.NonPublic, null, Response,null);
// next we go thru all elements of list and search our header
for(int i=0; i < fieldCustomHeaders.Count; i++)
{
// see all headers
PropertyInfo propHeaderName = fieldCustomHeaders[i].GetType().GetProperty("Name", BindingFlags.Instance|BindingFlags.NonPublic);
String headerName = (String)propHeaderName.GetValue(fieldCustomHeaders[i], null);
// if we find needed header
if(headerName == "Content-Encoding")
{
// get value of header from its field
FieldInfo fieldHeaderValue = _fieldCustomHeaders[i].GetType().GetField("_value", BindingFlags.Instance|BindingFlags.NonPublic);
String headerValue = (String)fieldHeaderValue.GetValue(fieldCustomHeaders[i]);
// if we find needed value
if (headerValue == "gzip")
{
// just set new value to it
fieldHeaderValue.SetValue(_fieldCustomHeaders[i], "deflate");
break;
}
}
}