我使用WebMarkupMinMvc来压缩html,如下所示:
[CompressContent]
[MinifyHtml]
[OutputCache(CacheProfile = "CacheCompressedContent5Minutes")]
public ActionResult Index()
{
…
}
这是在本地工作,但我发布了网站,并将其加载到服务器。我收到错误:
我无法调试它,因为它正在本地工作。关于这个话题的任何想法?
修改
当我手动编写过滤器属性时,我处理了错误:response.Filter
为空,因此我收到错误。
public class CompressFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (filterContext.IsChildAction) return;
HttpRequestBase request = filterContext.HttpContext.Request;
string acceptEncoding = request.Headers["Accept-Encoding"];
if (string.IsNullOrEmpty(acceptEncoding)) return;
acceptEncoding = acceptEncoding.ToUpperInvariant();
HttpResponseBase response = filterContext.HttpContext.Response;
if (acceptEncoding.Contains("GZIP"))
{
response.AppendHeader("Content-encoding", "gzip");
response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
}
else if (acceptEncoding.Contains("DEFLATE"))
{
response.AppendHeader("Content-encoding", "deflate");
response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
}
}
}
那么,我该如何解决呢?