The benefits of Gzip compression on the Web site believe that many people are already aware that doing so can improve the performance of the site. So why do many websites not have Gzip compression enabled? There are 4 reasons: antivirus software, browser bugs, site agents, and servers are not configured.
The accept-encoding request header is not sent when using IE6, so the Gzip compression feature is not supported, so call us to use Google Chrome. In ASP. 3, we implemented Actionfilter by implementing the following:
Public Class Compressattribute : ActionFilterAttribute{ Public Override void OnActionExecuting(ActionExecutingContextFiltercontext) { VarAcceptencoding=Filtercontext.HttpContext.Request.Headers["Accept-encoding"]; If (!String.IsNullOrEmpty(Acceptencoding)) {Acceptencoding=Acceptencoding.ToLower(); VarResponse=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); } } }< Span class= "PLN" >}
This allows us to add [Compress] on the Action to implement gzip compression to achieve gzip compression, as follows:
[Compress]publicactionresultIndex(string ID)
Here we've implemented gzip compression in ASP. NET MVC 3, and we can use Google Chrome to see if gzip compression is properly implemented. Use the shortcut key ctrl+shift+j to open the developer tools and view the results, such as finding that Gzip compression has been implemented:
This is the first article of the ASP. NET MVC 3 site optimization, and there are several articles behind me that I will be sorting out, hoping to help improve the performance of ASP. NET MVC 3.
ASP. NET MVC 3 website Optimization Summary (i) using Gzip compression