How do I remove eTag headers from IIS7?

后端 未结 12 1995
旧巷少年郎
旧巷少年郎 2020-12-04 07:28

Per Yahoo\'s best practices for high performance web sites, I\'d like to remove Etags from my headers (I\'m manually managing all my caching and have no need for Etags... an

12条回答
  •  攒了一身酷
    2020-12-04 08:23

    I wrote a custom http module to handle this. It's really not as bad as it sounds. Here's the code:

    using System;
    using System.Web;
    
    namespace StrongNamespace.HttpModules
    {
        public class CustomHeaderModule : IHttpModule
        {
            public void Init(HttpApplication application)
            {
                application.PostReleaseRequestState += new EventHandler(application_PostReleaseRequestState);
    
            }
    
            public void Dispose()
            {
            }
    
            void application_PostReleaseRequestState(object sender, EventArgs e)
            {
                HttpContext.Current.Response.Headers.Remove("Server");
                HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
                HttpContext.Current.Response.Headers.Remove("ETag");
            }
        }
    }
    

    Here's the web.config changes you'll want:

    
        
            
                
                    
                
            
            
                
            
        
    
    

提交回复
热议问题