<p>Basically, I'm trying to write the following (pseudocode) in an ASP.NET HttpModule:</p>

<pre><code>*pre-code*
try { handler.ProcessRequest(...) }
catch (Exception) { *error-code* }
finally { *post-code* }
</code></pre>

<p>I've found that I can hook into HttpModule.PreExecuteHandler for "pre-code" and .Error for "error-code".  But PostExecuteHandler doesn't seem to be running reliably.</p>

<p>BeginRequest and EndRequest run reliably but are too early for the code I need to write, which requires inspection of the handler that was chosen to execute.  The handler isn't chosen until after BeginRequest.</p>

<p>Is there a best practice for writing this kind of wrapper?</p>

<p>Thanks!</p>

Add this to your Global.asax file:
```
```
protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
    //
}

protected void Application_PostRequestHandlerExecute(object sender, EventArgs e)
{
    //
}
```
```
That should work 100%.