Is it possible to add response http headers in web.config?

后端 未结 6 997
挽巷
挽巷 2020-12-29 02:35

In my application I need to set a http response header. I\'d like to do this in web.config.

6条回答
  •  难免孤独
    2020-12-29 03:26

    Solution Finally, after a long search I found the solution. Create a class with this code:

    public class myHTTPHeaderModule : IHttpModule
    {
    
        #region IHttpModule Members
    
        public void Dispose()
        {
    
        }
    
        public void Init(HttpApplication context)
        {
            context.EndRequest += new EventHandler(context_EndRequest);
        }
    
        void context_EndRequest(object sender, EventArgs e)
        {
            HttpResponse response = HttpContext.Current.Response;
    
            response.AddHeader("Content-Language", "*");
    
        }
    
        #endregion
    }
    

    (Don't ask me why to use this event, but it works..)

    Now add a line in web.config in the HttpModule section:

        
            
            
        
    

    And that's it!

提交回复
热议问题