ASP.net VB.net set up a static global variable

Hi

In ASP.net, what VB.net code do I use to set up and use a static global variable.
I want to apply a string value to it that can be used all over the project
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
 
Obadiah ChristopherConnect With a Mentor Commented:
Declare a static property in your application.

public class Class1
    {
        public static int MyProperty { get; set; }
    }

// Inside the global.asax file Application_Start event initialize it's value
protected void Application_Start(object sender, EventArgs e)
        {
Class1.MyProperty = 1;    
}

Now you can access this property anywhere from the application.
0
 
Kyle AbrahamsConnect With a Mentor Senior .Net DeveloperCommented:
I usually put something like that in the web.config so it can be configured later.



eg:

<appSettings>
   <key ="MyKey" value = "MyValue" />
</appSettings>

in code:

dim mystring as string = ConfigurationManager.AppSettings("MyKey")


More info:
http://msdn.microsoft.com/en-us/library/610xe886.aspx#Y85
0
 
ktromp1Commented:
Try doing a little more digging before asking here. Found this example that seems to be the solution to your problem rather quickly.

http://stackoverflow.com/questions/4508606/global-variable-in-asp-net-website
0
 
CodeCruiserConnect With a Mentor Commented:
You can also use session. Add something to session

Session("MyVar") = MyVal

and you can access it anywhere else.
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much for the information
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.