using ;
using ;
using ;
using ;
public class CompressAttribute : ActionFilterAttribute
{
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
//If an error occurs, no compression is performed, otherwise the page will appear garbled, rather than the yellow page with an error.
if ( != null)
return;
HttpResponseBase Response = as HttpResponseBase;
//Discern whether GZip or DeflateStream is enabled in IIS or other bearer devices
if ( is GZipStream || is DeflateStream)
return;
//Start to enter the compression process
string AcceptEncoding = ["Accept-Encoding"];
if (!(AcceptEncoding) && (("gzip") || ("deflate")))
{
if (("gzip"))
{
= new GZipStream(, );
("Content-Encoding");
("Content-Encoding", "gzip");
}
else
{
= new DeflateStream(, );
("Content-Encoding");
("Content-Encoding", "deflate");
}
}
}
}