Search code examples
c#asp.netsitecoreoutputcacheoutput-caching

Is it possible to get the currently evaluated control from Global.asax.GetVaryByCustomString()?


We have an ASP.NET Web Forms Sitecore site, where we are using HTML output caching using the OutputCache directive, VaryByCustom attribute, and an added GetVaryByCustomString() method in Global.asax.

Is it possible to get a handle to the current control from the GetVaryByCustomString() method? We're running into a problem with output caching using this method and multiple instances of a control added to the same page. If I had a handle to the control, I could cache the output separately based on its Sitecore parameters (important in this case) and still make it mesh nicely with the rest of our caching strategy.


Solution

  • It does not appear to be possible to get the currently evaluated code from GetVaryByCustomString() in Global.asax . However since my original goal was to vary cached output for a Sitecore control appearing multiple times in the same page, I found that this could be achieved by listing all controls in the page, then incrementing a counter attached to the request context during creation of each cache key and appending it to the key, since the controls are laid out in a deterministic and reliable order.