1

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.

ThomasD
  • 2,464
  • 6
  • 40
  • 56
  • Managing output caching at the Control level is very quirky. You might look into HttpResponse.AddCacheDependency(). – RickNZ Jan 02 '12 at 11:11
  • I haven't got things working, so my plan is to include two versions of the user control on my page. One for outputcaching and one for edit-mode. When edit-mode is required the outputcached control will be hidden (I will surround the outputcached control with a div-tag to control visibility) and the edit-mode-control will be shown. If something is edited I will invalidate the outputcached-control (I have already this working using addcacheitemdependency). In order to do this, I need to set caching on page_load or page_init on the user control (to first check for edit-mode). Is that possible? – ThomasD Jan 03 '12 at 06:02

0 Answers0