How can I reference data from an AppState variable?

后端 未结 1 1988
别跟我提以往
别跟我提以往 2021-01-29 11:18

The problem is that I can\'t find a way to test anything stored in AppState[\"variableName\"] (or App.variableName or HttpContext.Current.Application[\"variableName\"], etc.) in

相关标签:
1条回答
  • 2021-01-29 12:13

    The problem here is that casting is needed, without a space between the cast and the AppState variable. At the time that I posted this question, I was still so new (well, still am really) to C# server side programming. An example of what works is:

    if ((string)AppState["myVariable"] == "someString")
    {
        //do some stuff
    }
    

    Also, whether many people like the term "global variable" or not, the AppState variable is, in fact, considered a global variable. This is clearly stated in Mike Brind's Mikesdotnetting article "Tranferring Data Between ASP.NET Web Pages" in the very first line under Application Variables:

    "Application variables are also known as global variables." --(Mikesdotnetting)
    

    Also, if you (whoever you are) have not read this article and are either new to WebMatrix or want to see all of the options for transferring data between pages in WebMatrix, please do yourself a tremendous favor and read this easy-to-read, well-written, and highly educational article found here:

    http://www.mikesdotnetting.com/Article/192/Transferring-Data-Between-ASP.NET-Web-Pages

    0 讨论(0)
提交回复
热议问题