AppState is a wrapper around application level variables, and will only work like that is razor files. When you try to reference an application level variable inside a class, you need to use HttpContext.Current.Application["IsSet"]. You should also check
to see if it is null before checking the value.
rcm01
Member
4 Points
16 Posts
Referencing an _AspStart.cshtml AppState setting in a .cs
Oct 14, 2010 08:53 PM|LINK
I'm using WebMatrix beta2 and still trying to get a handle on everything. How do you reference an AppState variable in a class?
For example:
In _AppStart.cshtml set AppState["IsSet"] = true
then in /app_code/myClass.cs check reference the AppState["IsSet"] value in something like
if ( AppState["IsSet"] ) {
//do something
}else{
//do the opposite
}
.cs c# webmatrix beta 2
Mikesdotnett...
All-Star
154852 Points
19855 Posts
Moderator
MVP
Re: Referencing an _AspStart.cshtml AppState setting in a .cs
Oct 14, 2010 09:56 PM|LINK
AppState is a wrapper around application level variables, and will only work like that is razor files. When you try to reference an application level variable inside a class, you need to use HttpContext.Current.Application["IsSet"]. You should also check to see if it is null before checking the value.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter