Geeks With Blogs

News Awarded Microsoft MVP C#.NET - 2007, 2008 and 2009

I am born in Bangladesh and currently live in Melbourne, Australia. I am a Microsoft Certified Application Developer MCAD Chartered Member (C# .Net)and born in Bangladesh.
I am founder and Chief Executive Officer of
Simplexhub, a highly experienced software development company based in Melbourne Australia and Dhaka, Bangladesh. Co-founder and core developer of Pageflakes
Simplexhub, is on its mission to build a smart virtual community in Bangladesh and recently launched beta an ASP.NET MVC application written in C#.NET.

Some of My Articles
Flexible and Plugin based .Net Application..
Mass Emailing Functionality with C#, .NET 2.0, and Microsoft® SQL Server 2005 Service Broker'
Write your own Code Generator or Template Engine in .NET
Shahed Khan blog
Here is the original post.

Scott Hanselman wrote today about P3P and adding headers, which got me thinking. For this site (however dead it is) I can control the actual server, so adding the P3P headers was easy. However I have a community site bubbling under and if it takes off it will be need to be moved somewhere professional and not my attic. With professional hosting comes that lack of control and the need to have a better way of adding headers, and Scott made a throw away comment that sparked a day of fun;

If you don't have access to your IIS instance or your ISP doesn't want to help you out, you can also add these HTTP Headers programmatically using an HttpModule.

So I present to you idunno.Web.HttpHeaders. This is a configurable HttpModule, allowing you to use web.config to specify what headers and values you wish added to requests. I will freely admit to taking the shell from Blowery's HTTP Compression module and it works pretty much the same. Add the right lines to your web.config and away you go.

First add the references to the configuration section <configSections>
  <sectionGroup name="idunno.web">
    <section name="httpHeaders"
      type="idunno.Web.HttpHeaders.SectionHandler, idunno.Web.HttpHeaders"/>

Then add the configuration section

      <add name="X-Test" value="pigeon" />
      <remove name="X-Powered-By" />
      <add type="image/jpeg"/>
      <add type="image/gif"/>
      <add path="NoCustomerHeaders.aspx"/>

And finally add the module into the pipeline

    <add name="HttpHeadersModule"
      type="idunno.Web.HttpHeaders.HttpModule, idunno.Web.HttpHeaders"/>

Note that if you use the same name as an existing header your value should overwrite the existing value.

Posted on Wednesday, August 9, 2006 9:46 PM | Back to top

Comments on this post: Http Headers programmatically using the HttpModule

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Shahed Khan | Powered by: