Can't access ApplicationState from MVC Controller

Posted on 2014-08-05
Last Modified: 2014-08-06
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?
Question by:dyarosh
    LVL 74

    Accepted Solution

    string s = HttpContext.Application["MyString"] as string;

    Open in new window


    Author Closing Comment

    Thank you.  I had to use HttpContext.Current.Application["MyString"].
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    Hmmm...   It worked for me as I posted. Nevertheless, glad you got it working  = )


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now