Andre Pena
Andre Pena

Reputation: 59416

In what situation Application_EndRequest is called but Application_BeginRequest is not called?

The expected order of HttpApplication methods is:

  1. Application_Start
  2. Init
  3. Application_BeginRequest
  4. Application_AuthenticateRequest
  5. (page life cycle)
  6. Application_EndRequest

I'm passing through a situation, which throws absolutely no exception, in which, after the Init, it goes directly to ApplicationEndRequest. It doesn't call Application_BeginRequest neither initiates the page life cyle.

What do I do?

Upvotes: 9

Views: 3357

Answers (2)

srk
srk

Reputation: 1901

I observed that Application_BeginRequest is not called when I use the IIS Rewrite Module to return a 301 redirect. The only event I see called in this scenario is Application_EndRequest.

Here is my rewrite rule from web.config:

<rule name="HTTPS force" enabled="true" stopProcessing="true">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTPS}" pattern="^OFF$" />
  </conditions>
  <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>

This is obviously a very specific scenario. Not sure what general rule applies here.

Upvotes: 0

Andre Pena
Andre Pena

Reputation: 59416

Application_EndRequest is called but not Application_BeginRequest when theres an unhandled exception prior to Application_BeginRequest.

That may be on Application_Start, the initialization of some module or at Application_Init

Upvotes: 10

Related Questions