How can I define global variable what is available for each pages? I tired to use PageData. I've put it into _PageStart. When I open a page then the stored value in the PageData is reseted because of it runs each time when I open a page...
If you name a file _AppStart.cshtml and add it to the root folder, you can set global values in that. _AppStart.cshtml runs once when the application first starts.
GViktor
None
0 Points
4 Posts
Global variable - WebMatrix - Webpages C#
Jul 26, 2011 02:10 PM|LINK
Hi Everybody,
How can I define global variable what is available for each pages? I tired to use PageData. I've put it into _PageStart. When I open a page then the stored value in the PageData is reseted because of it runs each time when I open a page...
Any solution?
Thanks, Viktor
pranavkm
Participant
796 Points
106 Posts
Re: Global variable - WebMatrix - Webpages C#
Jul 26, 2011 02:51 PM|LINK
There's a property called App that could be used to share data across all pages and user sessions.
Use the Session property if you want to share data across all pages on a per-user basis.
Mikesdotnett...
All-Star
154927 Points
19867 Posts
Moderator
MVP
Re: Global variable - WebMatrix - Webpages C#
Jul 26, 2011 07:41 PM|LINK
If you name a file _AppStart.cshtml and add it to the root folder, you can set global values in that. _AppStart.cshtml runs once when the application first starts.
@{ App.Discount = 10; App.Color = "Blue"; //etc... }Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
GViktor
None
0 Points
4 Posts
Re: Global variable - WebMatrix - Webpages C#
Jul 27, 2011 12:22 PM|LINK
Thanks for quick support!
Scal
Member
400 Points
129 Posts
Re: Global variable - WebMatrix - Webpages C#
Jul 27, 2011 04:29 PM|LINK
Or use the Web.Config file and retrieve value with the Configuration Manager