How to add Header and Footer on every page by using HttpModule in

In this post,I will show you a very simple way to add header and footer on every page using HttpModule.

  • Open visual studio and create a new website.
  • Right click on website and add a new class named HeaderAndFooter,and inherit this class with IHttpModule inteface.
using System;
using System.Web;
using System.IO;

public class HeaderAndFooter : IHttpModule
    const string PageHeaderText = "<h1>Header Added by Module<h1>";
    const string PageFooterText = "<h1>Footer added by Module</h1>";

    public void Init(HttpApplication app)
        // Register for pipeline events
        app.BeginRequest += new EventHandler(OnBeginRequest);
        app.EndRequest += new EventHandler(OnEndRequest);

    public void Dispose()
        // Nothing to do here

    public void OnBeginRequest(object sender, EventArgs e)
        HttpApplication app = (HttpApplication)sender;
        HttpContext ctx = app.Context;

        // Add custom header to the HTTP response
        ctx.Response.AppendHeader("Author", "DinoE");

    public void OnEndRequest(object sender, EventArgs e)
        // Get access to the HTTP context 
        HttpApplication app = (HttpApplication)sender;
        HttpContext ctx = app.Context;

        // Append some custom text
  • Open the web.config and register the module as below
<?xml version="1.0"?>
  For more information on how to configure your ASP.NET application, please visit
      <add name="HeaderAndFooter" type="HeaderAndFooter,App_Code"/>
    <compilation debug="true" targetFramework="4.0"/>


  1. Such a wonderful post. Development is one of the most popular application development now-a-days. We are also providing some good tips related to this post.Great work. Application Development

  2. Ya this right now day development is the most popular for online web business. it is very good stuff.