ASP.NET HttpApplication.EndRequest event not fired


ASP.NET HttpApplication.EndRequest event not fired



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.




Drag and drop in ASP.NET

1:



Using JQuery in a Subfolder When the MasterPage is in the Root Folder
You can use your own HttpModule to capture the EndRequest if you don't want to use the global.asax..
Silverlight 2 - Download file - IE Blocks file download
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.
Issues rendering UserControl using Server.Execute() in an ASMX web service
<httpModules>     <add name="CustomModule" type="CustomModule"/> </httpModules> 


How can I configure ASP.Net membership providers through code?


ASP.net Page Loading popup

2:



ContentType doesnt work, mime=application/octet-stream
Per the MSDN documentation, this event occurs AFTER the page is completed, just like BeginRequest.


Html To Doc(Word) Or RTF Format
Therefore as far as I know it is not possible to catch this at the page level.


3:


I believe a better way to chain this event is by providing a base class to global.asax.
Language="C#" Inherits="YourBaseClass" 
and then overriding Init():.
public override void Init() {     base.Init();      BeginRequest += new EventHandler(OnBeginRequest);     EndRequest += new EventHandler(OnEndRequest); } 
seems to be working for me (catch a breakpoint) but I'm really doing anything with it.. Since there are multiple HttpApplication instances, setting it within Page_load may keep adding it to a non-specific instance.

Oddly, I've also noticed that HttpApplication.Init() does not get called for the very first HttpApplication instance (but Application_start) does..


4:


The page is probably being disposed before the event fires.

You might want to try to do your work in the Page_Unload handler..



85 out of 100 based on 55 user ratings 805 reviews