Using ASP.NET MVC3.
What I'm trying to do is initialize a Controller field/property with an Application state variable.
I.e. in my Application_Start() method I have
Application["stats"] = new Stats(); //this is fine
Accessing this via a Controller method, e.g.
public ActionResult Index()
{
return View(HttpContext.Application["stats"]); //this is also fine
}
works fine too.
//blows up with a 'Object reference not set to an object' error.
private Stats stats;
public HomeController()
{
stats= (Stats)(HttpContext.Application["stats"]);
}
Anyone able to explain what I'm failing to understand + how to go about fixing the problem ? If there's a better way, let me know (and just in case you're wondering, I'm not trying to load up application configuration or anything; just to keep live stats on the state of the website)
Thanks in advance
-Marcin