Access to application state off page

I am trying to access the state of an application from a utility class in a web application, but I'm not sure if this is the best way to do this. I was looking for a static member, but there is no use (I was thinking somewhere along the lines of HttpContext.Current).

The best solution that I have found so far is to have a member in the utility class that will be initialized in the Application_Start event for Global.asax.cs (I can get it from this.Application there), but will there be any or is the risk of "something" happening with this link (I don’t care about restarting the application, because I am only looking for a cache function)?

+5
source share
4 answers

I think I get it!

HttpContext.Current.Application
+8
source

Unable to access application state outside HTTTPContext by design. Using Application_Start is the preferred way to initialize "global" values. You can also use the class Cachefor the same purpose. Cacheoffers membership expiration features that can be useful for data that changes due to events such as a file or database change.

+1
source

System.Web.HttpRuntime
0

:

public class MyGlobalCache
{
    public static string SomeValue{get;set;}
}

This is saved at the application level, which means that you get the same functionality of the application state. A static member will be available in all layers (web pages and not web pages).

0
source

All Articles