• HttpContext中的Cache与Items


    1.HttpContext.Cache
    有关缓存,可以参考这篇文章:
    http://www.cnblogs.com/abac/archive/2004/02/11/1166.aspx
    它提到:
    Asp.net中,提供了专门用于缓存数据的Cache对象,它的应用范围是应用程序域。生存期是和应用程序紧密相关的,每当应用程序启动的时候就重新创建Cache对象。它域Application对象的主要区别就是提供了专门用于缓存管理的特性,比如依赖和过期策略。
    你可以使用Cache对象和它的属性来实现高级的缓存功能,同时可以利用Asp.net Cache来对客户端输出的响应内容进行缓存。

    2.HttpContext.Items
    参考文章:http://odetocode.com/Articles/111.aspx
    它提到:
    First, let’s be clear and state that what you keep in the Items collection will have a very limited scope. Anything you place into the Items collection will only be around for the duration of a single web request, unlike the Session collection, which will keep it’s contents around for each user as long as they continue to make requests. Nevertheless, we will demonstrate several useful techniques with the Items collection in this article.
    HttpContext.Items的作用域是一个独立的Web请求。有关它的作用域,它举了个例子:
    在页面WebForm1.aspx的Page_Load中加入:
    ...
    Context.Items["WebForm1List"] = list;
    Server.Transfer("WebForm2.aspx");

    然后在WebForm2.aspx的Page_Load中加入:
    ArrayList list = Context.Items["WebForm1List"] as ArrayList;
    结果运行正常,但将Server.Transfer换成Response.Redirect
    就不行了原因是重定向使用了新的HTTP request然后将会有新的Context而此时的Context并不是原先我们在WebForm1.aspx中放有list的Context了。


  • 相关阅读:
    Python Install for windows X64
    CentOS 7 Install Gitlab CE
    centos 7安装vmtools时提示The path "" is not a valid path to the xxx kernel headers.
    Jenkins install
    gradle 编译 No such property: sonatypeUsername错误解决
    Hololens 开发环境配置(转)
    Krapo 2
    Krapno 1
    dubbo 常见错误
    groupby
  • 原文地址:https://www.cnblogs.com/huqingyu/p/17126.html
Copyright © 2020-2023  润新知