I have a list of items which are output-cached in a user control. If an administrator is logged in, I would like to add a delete button to each of the items.
Without output-caching I check whether the current user is member of the administrator role and show/hide the button accordingly. Since the list is now output-cached I cannot do that.
I looked at the substitution control, but first of all it returns a string and not a full control, second of all it is a static method, so I cannot access the ItemId, which I have added as a property to each item in the list.
What would be the right way of adding the delete-button to my list?
UPDATE I have tried adding the following to the page_load of my page as well as on the user control:
this.Response.DisableKernelCache();
HttpCacheValidateHandler val = new HttpCacheValidateHandler(ValidateCache);
this.Response.Cache.AddValidationCallback(val, null);
and
public static void ValidateCache(HttpContext context, Object data, ref HttpValidationStatus status)
{
if (context.User.IsInRole("administrator"))
status = HttpValidationStatus.Invalid;
else
status = HttpValidationStatus.Valid;
}
I have decorated my user control with:
[PartialCaching(3600, VaryByCustom = "Page", VaryByParams = "paging")]
I am creating the site with the open source CMS Umbraco, so the VaryByCustom="Page" varies the cache by the current documentnode in the CMS. VaryByParams="paging" varies the list by a "paging"-urlparameter (page1, page2 etc in the list)
The ValidateCache-method is never called.