You can create your own routing handler, which may be early enough in the pipeline to achieve your goal.
public class MyRoutingHandler : IRouteHandler
{
protected virtual IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return new InterceptingMvcHandler(requestContext);
}
IHttpHandler IRouteHandler.GetHttpHandler(RequestContext requestContext)
{
return GetHttpHandler(requestContext);
}
}
and the corresponding mvc handler:
public class InterceptingMvcHandler : MvcHandler
{
public InterceptingMvcHandler(RequestContext requestContext) : base(requestContext)
{
}
protected override IAsyncResult BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, object state)
{
httpContext.Response.Write("<h2>BeginProcessRequest</h2>");
return base.BeginProcessRequest(httpContext, callback, state);
}
protected override void EndProcessRequest(IAsyncResult asyncResult)
{
var context = RequestContext.HttpContext;
base.EndProcessRequest(asyncResult);
if (context != null)
{
context.Response.Write("<h2>EndProcessRequest</h2>");
}
}
}
You can then register the mvc handler in your route registers.
source
share