Skip to content

TerribleDev/CompressR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CompressR is a set of nuget packages that help you implement compression on your MVC, and WebApi Actions

install-package CompressR.MVC5

public class HomeController : Controller
    {
        [Compress]
        public ActionResult Index()
        {
            ViewBag.Title = "Home Page";

            return View();
        }
        [Gzip]
        public ActionResult About()
        {
           

            return View();
        }
    }

install-package CompressR.WebApi

public class ValuesController : ApiController
    {
        [Compress]
        // GET api/values
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/values/5
        public string Get(int id)
        {
            return "value";
        }

        // POST api/values
        public void Post([FromBody]string value)
        {
        }

        // PUT api/values/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/values/5
        public void Delete(int id)
        {
        }
    }

Owin

You can add gzip support through a middleware. Install the package: Install-Package CompressR.Owin. Then add app.Use<GzipMiddleware>(); to your Startup.cs.

        public void Configuration(IAppBuilder app)
        {
            app.Use<GzipMiddleware>();
            app.Run(context =>
            {
                context.Response.ContentType = "text/plain";
                return context.Response.WriteAsync("Hello World!");
            });
        }