HttpContext (C#) : HTTP Modules « Development « ASP.NET Tutorial






using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace Demo
{
    public class AppendMessage : IHttpModule
    {
        private HttpContext _current = null;

        #region IHttpModule Members

        public void Dispose()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public void Init(System.Web.HttpApplication context)
        {
            _current = context.Context;

            context.PreSendRequestContent +=
                new EventHandler(context_PreSendRequestContent);
        }

        void context_PreSendRequestContent(object sender, EventArgs e)
        {
            string message = "<!-- This page has been post processed at " +
                             System.DateTime.Now.ToString() +
                             " by a custom HttpModule.-->";

            _current.Response.Output.Write(message);
        }

        #endregion
    }
}
File: Web.config


 
<configuration>
    <system.web>
      <httpModules>
        <add name="AppendMessage" type="AppendMessage, App_code" />
      </httpModules>
    </system.web>
</configuration>








9.25.HTTP Modules
9.25.1.Creating Custom HTTP Modules
9.25.2.HttpContext (C#)
9.25.3.HttpContext (VB)
9.25.4.URL rewriting HttpModule (C#)
9.25.5.URL rewriting HttpModule (VB)
9.25.6.The IHttpHandler page template (C#)
9.25.7.The IHttpHandler page template (VB)
9.25.8.Outputting an image from an HttpHandler (C#)
9.25.9.Outputting an image from an HttpHandler (VB)
9.25.10.Adding the HttpHandler configuration information to web.config
9.25.11.HttpModule Tester