How to attach custom ICallHandler with aspx page class using Matching Rule

Topics: Building and extending application blocks, Enterprise Library Core, Exception Handling Application Block, General discussion, Policy Injection Application Block
Jan 20, 2012 at 5:56 AM


I want to attach one custom ICallHandler and ExceptionCallHandler with my UI layer (.aspx pages code behind) using policy injection (unity block).

Since for the policy injection one of two conditions are required:-

1) Class inherits from MarshelByRef


2) Class inherits from some interface

Since .aspx page inherits from the System.Web.UI.Page class, we can't inherits it from the MarshelByRef class and we don't have any interface to implement on Page.

How can I attach the custom ICallHandler or ExceptionCallHandler with aspx page class using the matching rule in web.config file.

Jan 20, 2012 at 9:45 PM

I don't think that your approach fits with Unity.  Besides trying to figure out what interceptor to use (the ones you rightly mention don't fit the bill -- the only one that would have a chance of working would be the VirtualMethodInterceptor).  However, the reason is that the ASP.NET pipeline controls all of the object creation so you you would have to somehow hook into that and override the object creation to use Unity.  Not sure if that is even possible.  Even if it was, I wouldn't recommend it as a solution.  Perhaps you could move all of your logic to classes that can be intercepted and have the page invoke those classes?

See Intercept Unity 2.0 HandlerAttribute without an interface question and answer for some additional information.

Randy Levy
Enterprise Library support engineer