代码之家  ›  专栏  ›  技术社区  ›  spender

在asp.net mvc中是否可以按成员身份进行缓存?

  •  2
  • spender  · 技术社区  · 15 年前

    我们有一堆流量非常大的页面,因此我们在web.config中有以下内容:

    <caching>
      <outputCacheSettings>
        <outputCacheProfiles>
          <add name="defaultCache" duration="900" varyByParam="*" location="Any"/>
        </outputCacheProfiles>
      </outputCacheSettings>
    </caching>
    

    以及必要控制器方法的以下属性:

    [OutputCache(CacheProfile = "defaultCache")]
    

    那么,有没有按角色缓存的方法?如果页面的url保持不变,但内容根据登录的角色而变化,这是否可能?通过在所有相关页面中添加像?admin=true这样的内容来改变URL是否更好 varyByParam="*" 缓存配置文件上的属性可以完成它的工作吗?

    1 回复  |  直到 15 年前
        1
  •  3
  •   Jaroslav Jandek    15 年前
    <add name="defaultCache" duration="900" varyByParam="*" varyByCustom="membership" location="Any"/>
    

    public override string GetVaryByCustomString(HttpContext context, string custom)
    {
        if (custom == "membership")
        {
            string membership = "";//Get membership.
            return membership;
        }
    
        return string.Empty;
    }