• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 145
  • Last Modified:

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?
0
dyarosh
Asked:
dyarosh
  • 2
1 Solution
 
käµfm³d 👽Commented:
string s = HttpContext.Application["MyString"] as string;

Open in new window

0
 
dyaroshAuthor Commented:
Thank you.  I had to use HttpContext.Current.Application["MyString"].
0
 
käµfm³d 👽Commented:
Hmmm...   It worked for me as I posted. Nevertheless, glad you got it working  = )

Screenshot
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now