27 lines
885 B
C#
27 lines
885 B
C#
using System;
|
|
using System.IO.Compression;
|
|
using System.Linq;
|
|
|
|
namespace CompressR.MVC
|
|
{
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
|
|
public sealed class GzipAttribute : System.Web.Mvc.ActionFilterAttribute
|
|
{
|
|
private bool RequireCompression { get; set; }
|
|
|
|
public GzipAttribute(bool requireCompression = false)
|
|
{
|
|
RequireCompression = requireCompression;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Override to compress the content that is generated by
|
|
/// an action method.
|
|
/// </summary>
|
|
/// <param name="filterContext"></param>
|
|
public override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext)
|
|
{
|
|
CompressFactory.Compress(Constants.Gzip, filterContext, RequireCompression);
|
|
}
|
|
}
|
|
} |