简体   繁体   中英

How do I add an event handler for every request in ASP.NET that will be handled by PageHandlerFactory

I want to configure an asp.net website so that for every request it executes my event handler(say for tracking/logging some info from request object) only if request will be handled by an PageHandlerFactory .

I know I can write it in Application_BeginRequest but that is called for every kind of request(be it *.axd or so ,Correct me if I'm wrong here). HttpContext.Current.CurrentHandler might be null at this time so I can't put conditional logic for handler type. For some reason(legacy business rules/checks) I can't move the my logic to Application_EndRequest .

Use can try using the httphandler and httpmodule in asp.net

it has an event LogRequest

LogRequest - Occurs just before ASP.NET performs any logging for the current request. The LogRequest event is raised even if an error occurs. You can provide an event handler for the LogRequest event to provide custom logging for the request.

Furthure in ASP.net we have

ASP.NET uses different HTTP handlers to serve different file types. For example, the handler for web Page creates the page and control objects, runs your code, and renders the final HTML. ASP.NET default handlers:

1) Page Handler (.aspx) – Handles Web pages 2) User Control Handler (.ascx) – Handles Web user control pages 3) Web Service Handler (.asmx) – Handles Web service pages 4) Trace Handler (trace.axd) – Handles trace functionality

You can get more insight at httphandler and httpmodule in asp.net

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM