加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

如何不缓存ASP.NET用户控件?

发布时间:2020-12-16 00:14:51 所属栏目:asp.Net 来源:网络整理
导读:我在我的页面中使用OutputCache,它有一个用户控件,但我不想缓存这个特定的用户控件,因为它与用户登录有关(如果我访问该页面,我看到该页面就像我通过身份验证一样另一个用户). 我怎样才能做到这一点? 解决方法 我个人使用VaryByCustom属性为登录和注销用户提
我在我的页面中使用OutputCache,它有一个用户控件,但我不想缓存这个特定的用户控件,因为它与用户登录有关(如果我访问该页面,我看到该页面就像我通过身份验证一样另一个用户).

我怎样才能做到这一点?

解决方法

我个人使用VaryByCustom属性为登录和注销用户提供不同的缓存页面视图:
<%@ OutputCache VaryByCustom="IsLoggedIn" Duration="30" VaryByParam="*" %>

然后在global.asax你放

public override string GetVaryByCustomString(HttpContext context,string arg)
{
    if (arg == "IsLoggedIn")
    {

        if (context.Request.IsAuthenticated)
        {
            return "Logged in: " + context.User.Identity.Name;
        }
        else
        {
            return "Not Logged In";
        }

    }
    else
    {
        return base.GetVaryByCustomString(context,arg);
    }

}

我只是想把它扔出去.替代控制怎么样?

http://msdn.microsoft.com/en-us/library/ms228212.aspx

根据msdn网站:

The Substitution control lets you
create areas on the page that can be
updated dynamically and then
integrated into a cached page. …
The Substitution control offers a
simplified solution to partial page
caching for pages where the majority
of the content is cached. You can
output-cache the entire page,and then
use Substitution controls to specify
the parts of the page that are exempt
from caching.

我从来没有亲自使用过替换控件,但是我刚好在前几天查看了它,听起来它可以以某种方式将更新的内容注入到其他缓存的页面输出中.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读