There seems to be three distinct methods of storing a variable that will be available for every request in an application:
Global.asax.cs
public class MvcApplication : HttpApplication
{
protected void Application_Start()
{
Application["SiteDatabase"] = new SiteDatabase();
}
}
OWIN:
public partial class Startup
{
public void ConfigureAuthentication(IAppBuilder Application)
{
Application.CreatePerOwinContext<SiteDatabase>(new SiteDatabase());
}
}
Static Container
public static class GlobalVariables
{
private SiteDatabase _Database;
public SiteDatabase Database
{
get { return _Database ?? new SiteDatabase(); }
}
}
What are the relative advantages of each method?
To store a value in a variableUse the variable name on the left side of an assignment statement. The following example sets the value of the variable alpha . The value generated on the right side of the assignment statement is stored in the variable.
Application variables are values that are available to any user or page within an application. For the first time, they can be any value you wish to store.
We can store local variables that can be accessed within the application by using app. locals.
application variable creates only one memory for one variable and for all user . while session creates one memory for one variable for one user :) Application variable will be maintained like global variable. Ex if I create a application session in my project and assign this value 1.
Answer: Variables are used for storing values such as strings, integers, list, dictionary etc.
One special thing about variables is that they can contain just about anything — not just strings and numbers. Variables can also contain complex data and even entire functions to do amazing things.
In order:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With