ASP.NET HttpModule - guaranteed execution of pre- and post-handler code?

Basically, I am trying to write the following (pseudocode) in an ASP.NET HttpModule:

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

I found that I can connect to HttpModule.PreExecuteHandler for "pre-code" and .Error for "error code". But PostExecuteHandler does not seem to work reliably.

BeginRequest and EndRequest work reliably, but it's too early for the code I need to write, which requires checking the handler that was selected to execute. A handler is not selected until BeginRequest.

Is there any best practice for writing this type of wrapper?

Thank!

+3
source share
2 answers

, ( , HttpModule), Response.End. Response.End , , Server.Transfer.

+2

Global.asax:

protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
    //
}

protected void Application_PostRequestHandlerExecute(object sender, EventArgs e)
{
    //
}

100%.

-2

Source: https://habr.com/ru/post/1699555/


All Articles