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
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)
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2015-06-23 一个解决方案下的多个项目共享一个AssemblyInfo
2015-06-23 8 Things Every Person Should Do Before 8 A.M.
2014-06-23 将DevExpress.Utils.ImageCollection变量的image导出
2014-06-23 VS不显示最近打开的项目