【发布时间】:2014-12-12 21:54:51
【问题描述】:
像 webmarkupmin 这样的插件使用这样的 HTTP 模块从 HTTPContext 修改 HTTP 响应正文:
protected override void ProcessContent(HttpContext context)
{
HttpRequest request = context.Request;
HttpResponse response = context.Response;
Encoding encoding = response.ContentEncoding;
string contentType = response.ContentType;
if (request.HttpMethod == "GET" && response.StatusCode == 200
&& contentType == ContentType.Html
&& context.CurrentHandler != null)
{
var htmlMinifier = WebMarkupMinContext.Current.Markup.CreateHtmlMinifierInstance();
response.Filter = new HtmlMinificationFilterStream(response.Filter, htmlMinifier,
request.RawUrl, encoding);
if (WebMarkupMinContext.Current.IsCopyrightHttpHeadersEnabled())
{
CopyrightHelper.AddHtmlMinificationPoweredByHttpHeader(response);
}
}
}
您将如何使用 ASP.NET 5 中的新 HTTP 管道修改每个请求的原始 HTTP 响应正文?
【问题讨论】:
-
应该添加这个:通过修改我的意思是读出响应正文作为字符串以便可以修改,然后将新内容设置为要发送的响应正文。
-
奇怪,好像 Response.Body.CanRead 属性不可设置...
标签: asp.net-core asp.net-core-mvc