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

148 Views Asked by At

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.

2

There are 2 best solutions below

0
Iucounu On BEST ANSWER

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.

1
Matthew Dresser On

I'm not sure why you would use custom code to do this caching. If you have a Sublayout for your control, then for each instance of that control/Sublayout on a page, you would activate caching by going to Presentation/Layout Details > Control Properties and scroll down to the Caching section. There you would check teh "Cacheable" and "Vary by Data" options.