Yanesh Tyagi writes …

October 22, 2007

HTTP Modules’ Events and Their Order of Firing

Filed under: .Net, Programming, Technology — yaneshtyagi @ 6:50 pm
Tags: ,

Below is the list of Events raised by HttpHandlers. These events are in the sequence of firing.

OnBeginRequest
OnAuthenticateRequest
OnPostAuthenticateRequest
OnAuthorizeRequest
OnPostAuthorizeRequest
OnResolveRequestCache
OnPostResolveRequestCache
OnPostMapRequestHandler
OnAcquireRequestState
OnPostAcquireRequestState
OnPreRequestHandlerExecute
Page_Load Event of the Page
OnPostRequestHandlerExecute
OnReleaseRequestState
OnPostReleaseRequestState
OnUpdateRequestCache
OnPostUpdateRequestCache
OnEndRequest
OnPreSendRequestHeaders

I wrote a http handler to check the sequence of execution of event handlers. Below is the program. Two events in the program are commented because these require integration with the IIS pipeline. I used Visual Web Developer 2008 Express Edition Beta 2 to write this program. So may be express edition does not support integration with IIS. I haven’t checked it yet. Here is the program:

using System;

using System.Data;

using System.Configuration;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Xml.Linq;

/// <summary>

/// Summary description for AddSign

/// </summary>

public class AddSign: IHttpModule

{

public delegate void MyEventHandler(Object s, EventArgs e);

private MyEventHandler _eventHandler = null;

public event MyEventHandler MyEvent

{

add { _eventHandler += value; }

remove { _eventHandler -= value; }

}

public AddSign()

{

//

// TODO: Add constructor logic here

//

}

#region IHttpModule Members

void IHttpModule.Dispose()

{

//throw new NotImplementedException();

}

void IHttpModule.Init(HttpApplication context)

{

//throw new NotImplementedException();

context.EndRequest += new EventHandler(OnEndRequest);

context.AcquireRequestState += new EventHandler(OnAcquireRequestState);

context.AuthenticateRequest += new EventHandler(OnAuthenticateRequest);

context.AuthorizeRequest += new EventHandler(OnAuthorizeRequest);

context.BeginRequest += new EventHandler(OnBeginRequest);

context.Disposed += new EventHandler(OnDisposed);

context.Error += new EventHandler(OnError);

//context.LogRequest += new EventHandler(OnLogRequest); //This operation requires IIS integrated pipeline mode.

//context.MapRequestHandler += new EventHandler(OnMapRequestHandler); //This operation requires IIS integrated pipeline mode.

context.PostAcquireRequestState += new EventHandler(OnPostAcquireRequestState);

context.PostAuthenticateRequest += new EventHandler(OnPostAuthenticateRequest);

context.PostAuthorizeRequest += new EventHandler(OnPostAuthorizeRequest);

context.PostMapRequestHandler += new EventHandler(OnPostMapRequestHandler);

context.PostReleaseRequestState += new EventHandler(OnPostReleaseRequestState);

context.PostRequestHandlerExecute += new EventHandler(OnPostRequestHandlerExecute);

context.PostResolveRequestCache += new EventHandler(OnPostResolveRequestCache);

context.PostUpdateRequestCache += new EventHandler(OnPostUpdateRequestCache);

context.PreRequestHandlerExecute += new EventHandler(OnPreRequestHandlerExecute);

context.PreSendRequestContent += new EventHandler(OnPreSendRequestContent);

context.PreSendRequestHeaders += new EventHandler(OnPreSendRequestHeaders);

context.ReleaseRequestState += new EventHandler(OnReleaseRequestState);

context.ResolveRequestCache += new EventHandler(OnResolveRequestCache);

context.UpdateRequestCache += new EventHandler(OnUpdateRequestCache);

}

#endregion

public void OnEndRequest(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnEndRequest<br />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnAcquireRequestState(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnAcquireRequestState”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnAuthenticateRequest(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnAuthenticateRequest”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnAuthorizeRequest(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnAuthorizeRequest”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnBeginRequest(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnBeginRequest”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnDisposed(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnDisposed”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnError(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnError”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

app.Context.Response.Write(“<BR />”);

_eventHandler(this, null);

}

public void OnLogRequest(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnLogRequest”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnMapRequestHandler(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnMapRequestHandler”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnPostAcquireRequestState(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnPostAcquireRequestState”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnPostAuthenticateRequest(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnPostAuthenticateRequest”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnPostAuthorizeRequest(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnPostAuthorizeRequest”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnPostMapRequestHandler(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnPostMapRequestHandler”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnPostReleaseRequestState(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnPostReleaseRequestState”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnPostRequestHandlerExecute(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnPostRequestHandlerExecute”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnPostResolveRequestCache(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnPostResolveRequestCache”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnPostUpdateRequestCache(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnPostUpdateRequestCache”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnPreRequestHandlerExecute(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnPreRequestHandlerExecute”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnPreSendRequestContent(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnPreSendRequestContent”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnPreSendRequestHeaders(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnPreSendRequestHeaders”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnReleaseRequestState(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnReleaseRequestState”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnResolveRequestCache(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnResolveRequestCache”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

public void OnUpdateRequestCache(Object s, EventArgs e)

{

HttpApplication app = s as HttpApplication;

app.Context.Response.Write(“OnUpdateRequestCache”);

app.Context.Response.Write(“<BR />”);

if (_eventHandler != null)

_eventHandler(this, null);

}

}

1 Comment »

  1. http://yaneshtyagi.spaces.live.com/blog/cns!F66AE167494DDA0!247.trak

    Comment by Anonymous — October 31, 2007 @ 6:07 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.