Substitution in ASP.NET 2.0 seems pretty cool. You can designate part of a page as being substituted even when the rest of the page is being cached using the OutputCache directive.
Under the covers what is happening is a HttpResponseSubstitutionCallback delegate is getting wired up to each part of the page that you want to be dynamic when the rest of the page is being cached. You can use either the Substitution control to do this for you or use inline code and call Response.WriteSubstitution.
The goofy thing about this though is that ASP.NET is trying to enforce that the target method of the delegate be static. At first glance this seems pretty logical because if the target method is in a Page, then that Page instance would have to stay alive as long as the delegate stayed alive.
The problem with the implementation is that all it is doing is checking to see if Delegate.Target is of type control (which is will be if the HttpResponseSubstitutionCallback points to a instance method on a Page or other Control derived class). I can create an instance of some other type and use one of its instance methods as the target method. If my non-Control derived instance holds onto a reference to the HttpContext or the Page itself, the apparent reason to enforce static methods only is subverted.
Does anyone know why they don't check Delegate.Method.IsStatic instead?
ASP.NET | ASP.NET 2.0 Comments [0]
Remember Me