路人甲:我有好几个ascx,它们所生成的页面要依赖于某一个session变量,即session不同,生成的页面也不同,这个session变量共有6种值,请问如何为这种ascx加上缓存呢?

Truly:请看代码

.ascx上增加自定义缓存参数
<%@ OutputCache Duration="30" VaryByParam="None" VaryByCustom="custom" %>


Global.asax.cs
增加如下方法
public override string GetVaryByCustomString(HttpContext context, string arg)
{
      if (arg.ToLower () == "custom")
      {
            if(Session["test"] != null)
                  return Session["test"].ToString();
      }
      return base.GetVaryByCustomString (context, arg);
}


 

相关文章:

  • 2022-12-23
  • 2021-12-15
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2022-02-13
  • 2021-09-28
  • 2021-09-01
猜你喜欢
  • 2022-02-22
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
  • 2022-12-23
  • 2022-01-08
相关资源
相似解决方案