views:

113

answers:

1

I just upgraded my site from ASP.NET 3.5 to 4.0. I've been working through some breaking changes and there were more than I expected.

One I can't figure out, however, is why my <asp:Substitution /> control suddenly stopped working like it should. It's supposed to ignore the output cache settings of the parent page and update upon every request. For some reason that isn't happening. It's caching for the full 10 minutes (the OutputCache setting for my home page). Any ideas?

+1  A: 

<asp:Substitution> and other server controls are not supported in MVC. Response substitution in particular is intricately tied to the WebForms pipeline. The fact that it worked in MVC 1 was a happy accident but was not intentional.

The MVC team is working on ways to enable substitution caching in MVC 3 and beyond, but there will likely be MVC-specific mechanisms for doing this, so you shouldn't expect <asp:Substitution> or Response.WriteSubstitution() to work going forward. In the meantime, the best option is to output cache the entire page, then use Javascript / AJAX to have the client fill in the parts that need to be updated.

Levi
Thanks Levi. I found another workaround. I changed my strategy since there's really just one section of the page that benefits from being cached. As it turns out, one can use the OutputCache directive on a Partial View if you add it to your page as if it were a Web Forms control... http://www.highoncoding.com/Articles/638_Understanding_Partial_Views_in_ASP_NET_MVC_Application.aspx
Steve Wortham
I'd avoid using <%@ OutputCache %> on an .ascx, as it's also an ugly hack and is not guaranteed to work going forward (just like how substitution caching is broken). If you need to cache just a part of the page, consider using the [ChildActionCache] attribute from MVC Futures for ASP.NET 4 (http://aspnet.codeplex.com/releases/view/41742). This attribute can be applied to a method that is the target of an Html.RenderAction(), and just the contents of that RenderAction() will be cached for the specified period of time.
Levi

related questions