HTTP Modules are another way of handling any request or any error by the user . It also helps us to handle wrong request and errors in a customized manner.
Add the following code to ASP.NET Module
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(OnBeginRequest);
context.EndRequest += new EventHandler(OnEndRequest);
}
void OnEndRequest(object sender, EventArgs e)
{
HttpApplication appObject = (HttpApplication)sender;
HttpContext contextObject = appObject.Context;
// PageHeaderText is a constant string defined elsewhere
contextObject.Response.Write("<table width='100%' border='2'><tr><td align='center' background='Gray'>The last event in the HTTP pipeline chain of execution</td></tr></table>");
}
void OnBeginRequest(object sender, EventArgs e)
{
HttpApplication appObject = (HttpApplication)sender;
HttpContext contextObject = appObject.Context;
// Add custom header to the HTTP response
contextObject.Response.AppendHeader("Author", "Himanshu Joshi");
// PageHeaderText is a constant string defined elsewhere
contextObject.Response.Write("<table width='100%' border='2'><tr><td align='center' background='Gray'>HTTP pipeline begins to process the
request</td></tr></table>");
}
And then add the httpmodule tag in Web.Config file
0 Comment(s)