Link to home
Start Free TrialLog in
Avatar of dyarosh
dyarosh

asked on

Can't access ApplicationState from MVC Controller

In my Application_Start method in the Global.asax I am setting the Application State to a string.  When I try and access it my controller I can't.  I thought I would access the Application State the same way as I do the Session State by saying:

string myvar = Application["MyString"];

When I try that, Application doesn't show up in Intellisense and I get the message: 'The name 'Application' does not exist in the current context'.

Here is a partial listing of my Application_Start method:
public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        Application["MyString"] = "some value";
    }
}

Open in new window


Can someone please tell me what I am doing wrong?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dyarosh
dyarosh

ASKER

Thank you.  I had to use HttpContext.Current.Application["MyString"].
Hmmm...   It worked for me as I posted. Nevertheless, glad you got it working  = )

User generated image