According this MSDN article HttpApplication.EndRequest can be used to close or dispose of resources. However this event is not fired/called in my application.
We are attaching the handler in Page_Load the following way:
HttpContext.Current.ApplicationInstance.EndRequest += ApplicationInstance_EndRequest;
The only way is to use the Application_EndRequest handler in Global.asax, but this is not acceptable for us.
You can use your own HttpModule to capture the EndRequest if you don't want to use the global.asax.
public class CustomModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.EndRequest += new EventHandler(context_EndRequest);
}
private void context_EndRequest(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
// use your contect here
}
}
You need to add the module to your web.config
<httpModules>
<add name="CustomModule" type="CustomModule"/>
</httpModules>
Per the MSDN documentation, this event occurs AFTER the page is completed, just like BeginRequest. Therefore as far as I know it is not possible to catch this at the page level
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With