I think MvcApplication
is a global singleton. I want to get the instance of MvcApplication
in the controller. Then I put the following code in controll
I believe the reason why the original code didn't work is because HttpContext is both a property of Controller and its own class. Within a subclass of Controller, HttpContext will resolve to the property and produce the error mentioned. To get around it, explicitly reference the HttpContext class with it's fully qualified name:
System.Web.HttpContext.Current.Application
Or, since the HttpContext property already returns the current HttpContext instance, you could use:
HttpContext.Application