response.AppendHeader() 替代 .NET Core
response.AppendHeader() replacement for .NET Core
我在派生 ActionFilterAttribute
的 class 的 OnResultExecuting()
方法中使用了 response.AppendHeader("Content-encoding", "gzip");
。但它 returns 错误如:
//HttpResponseBase response = filterContext.HttpContext.Response;
HttpResponse response = filterContext.HttpContext.Response;
response.AppendHeader("Content-encoding", "gzip");
'HttpResponse' does not contain a definition for 'AppendHeader' and no accessible extension method 'AppendHeader' accepting a first argument of type 'HttpResponse' could be found (are you missing a using directive or an assembly reference?)
The ASP.NET Core response headers 使用属性来表示大多数常见的 headers.
要在 .NET 6 中设置内容编码,请使用:
response.Headers.ContentEncoding = "gzip";
对于早期版本,您需要使用 the Append
extension method:
response.Headers.Append("Content-Encoding", "gzip");
我在派生 ActionFilterAttribute
的 class 的 OnResultExecuting()
方法中使用了 response.AppendHeader("Content-encoding", "gzip");
。但它 returns 错误如:
//HttpResponseBase response = filterContext.HttpContext.Response;
HttpResponse response = filterContext.HttpContext.Response;
response.AppendHeader("Content-encoding", "gzip");
'HttpResponse' does not contain a definition for 'AppendHeader' and no accessible extension method 'AppendHeader' accepting a first argument of type 'HttpResponse' could be found (are you missing a using directive or an assembly reference?)
The ASP.NET Core response headers 使用属性来表示大多数常见的 headers.
要在 .NET 6 中设置内容编码,请使用:
response.Headers.ContentEncoding = "gzip";
对于早期版本,您需要使用 the Append
extension method:
response.Headers.Append("Content-Encoding", "gzip");