3

If I want to store some Objects to share across pages and session which one should I use?

HttpContext.Current.ApplicationInstance.Application or HttpContext.Current.Application.

I was using HttpContext.Current.Application but just got confused between the two.

TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188

2 Answers2

5

They both refer to the same thing, the HttpApplicationState

scartag
  • 17,548
  • 3
  • 48
  • 52
  • Well that's what I thought, but wanted to confirm after some answer in msdn forum directed to a page where MS says that `Application` is just for backward compatibility to classic ASP. Thanks for clearing it. – TheVillageIdiot Jan 22 '13 at 01:48
3

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.

spoulson
  • 21,335
  • 15
  • 77
  • 102