zoukankan      html  css  js  c++  java
  • HttpContext.Current.ApplicationInstance.Application vs HttpContext.Current.Application

    HttpContext.Current.ApplicationInstance.Application vs HttpContext.Current.Application

    They both refer to the same thing, the HttpApplicationState

    Application and ApplicationInstance.Application are two versions of the same HttpApplicationState object.

    From the HttpApplicationState reference:

    A single instance of an HttpApplicationState class is created the first time a client requests any URL resource from within a particular ASP.NET application virtual directory. A separate single instance is created for each ASP.NET application on a Web server. A reference to each instance is then exposed via the intrinsic Application object.

    To summarize:

    • Application object is global to the web server.
    • ApplicationInstance.Application object is local to the application the request refers to. (e.g. site or virtual directory application)

    This is further explained in this blog post.

     Application Vs ApplicationInstance

    Application refers to global application state in Classic ASP. Application is really a global dictionary object that was introduced in Classic ASP for lack of any global variables.

    ASP.Net uses ApplicationIntance property to refer to application instance that is processing current request. Application instances are thread safe hence it is not required to lock the non static members. ASP.Net has Application object purely for backword compatibility so that you can easily migrate a Classic ASP application to ASP.Net. It is recommended that you store data in static members of the application class instead of in the Application object. This increases performance because you can access a static variable faster than you can access an item in the Application dictionary.

    You can use following guidelines when accessing non static members in ASP.Net
    • From the Global.asax, use the this or Me object.
    • From a page, every page includes a strongly-typed ApplicationInstance property.
    • From the HttpContext object, use the HttpContext.ApplicationInstance property (which you type as HttpApplication)
  • 相关阅读:
    05_XML的解析_01_dom4j 解析
    04_SSM框架整合(Spring+SpringMVC+MyBatis)
    03_入门程序(注解方式,掌握)
    02_入门程序(非注解方式,了解)
    01_SpringMVC流程架构图
    21_resultMap和resultType总结
    20_高级映射:多对多查询
    inline函数的总结
    【C++】C++函数重载的总结
    优先队列
  • 原文地址:https://www.cnblogs.com/chucklu/p/13183364.html
Copyright © 2011-2022 走看看