将回发按钮添加到输出缓存的用户控件
我有一个在用户控件中输出缓存的项目列表。如果管理员登录,我想为每个项目添加一个删除按钮。
如果没有输出缓存,我会检查当前用户是否是管理员角色的成员,并相应地显示/隐藏按钮。由于列表现在已输出缓存,我无法这样做。
我查看了替换控件,但首先它返回一个字符串而不是完整控件,其次它是一个静态方法,因此我无法访问 ItemId,我已将其作为属性添加到列表中的每个项目。
将删除按钮添加到我的列表的正确方法是什么?
更新 我尝试将以下内容添加到我的页面的 page_load 以及用户控件上:
this.Response.DisableKernelCache();
HttpCacheValidateHandler val = new HttpCacheValidateHandler(ValidateCache);
this.Response.Cache.AddValidationCallback(val, null);
并且
public static void ValidateCache(HttpContext context, Object data, ref HttpValidationStatus status)
{
if (context.User.IsInRole("administrator"))
status = HttpValidationStatus.Invalid;
else
status = HttpValidationStatus.Valid;
}
我用以下内容装饰了我的用户控件:
[PartialCaching(3600, VaryByCustom = "Page", VaryByParams = "paging")]
我正在使用开源 CMS Umbraco 创建网站,因此 VaryByCustom="Page" 会变化通过 CMS 中当前的 documentnode 进行缓存。 VaryByParams="paging" 通过“paging”url 参数(列表中的 page1、page2 等)改变列表。
ValidateCache 方法永远不会被调用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论