Compress and Etag web pages - IIS7
can dynamic pages be compressed and given an etag too?
Any ideas? I'm missing Apache quit开发者_如何学JAVAe a lot. Hope someone can help! :)
To enable dynamic compression, use Microsoft Web Platform Installer to ensure that "IIS: Dynamic Content Compression" is installed. Then open up IIS Manager and click on the server (or to a site if you only want to enable this for an individual site, gets stored in web.config under site root so be careful not to overwrite), and go to Compression and ensure "Enable dynamic content compression" is ticked. This is for IIS7, let me know if you want this for IIS6.
For etags on aspx pages add to Page_PreInit (or Page_Init if Master page):
if (Request.Headers["If-None-Match"] == "somekey")
{
Response.StatusCode = (int)System.Net.HttpStatusCode.NotModified;
Response.End();
}
And to Page_Load:
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetETag("somekey");
Where somekey could be the last modified date stored in the database for the page if it's some content management system.
精彩评论