Application object reads the syntax of the data:
' Read
Data =application ("Data name")
' Write
Application ("data name") = Data
Cases:
Dim i
Application (i) =application (i) +1
Application Data non-synchronous update:
Application.Lock ' Lock Object
Application (i) =application (i) +1
Application.UnLock ' unlock
Application life cycle:
Start with IIS, terminate the IIS stop action or shutdown
If there are two people: A and have visited a website in a classmate
1.
sessin["userid"] = "a";//indicates that as long as a does not log off, does not Wenlen to which page, string str = session["userid" Saves the initialization data, often used in: Page_Load event, verify Identity
Page_Load ()
{
if (session["userid"] = = NULL | | session["userid"] = = "")
{
Response.Redirect ("login page, login again");
}
Else
{
Render a page
}
}
2.
application["X"];
As long as the value is assigned, such as: application["X"]; Then a and can be shared to this value, can be used for counters, record site traffic
As long as one user is logged in, application["x"] + = 1;//plus a number indicating that a new user has just logged on
3.
this.viewstate["y"] = "ABCDE";
On this page, the this.viewstate["Y" value can be used as a global variable, as long as the page is not exited,
including refreshing the page, it will not be lost
application can store generic variables, or you can store objects that contain large amounts of data.
1 void Application_Start (object sender, EventArgs e)
2 {
3//code to run when the application starts
4 application["Count" = 0;
5 System.IO.FileStream fs = System.io.file.open (Server.MapPath ("Count.txt"), system.io.filemode.openorcreate);
6 System.IO.StreamReader sr = new System.IO.StreamReader (FS);
7 application["allusers"] = Convert.ToInt32 (Sr.readline ());
8 Sr.close ();
9 Fs.close ();
10}
One void Application_End (object sender, EventArgs e)
12 {
13//code to run when the application shuts down
14
15}
void Application_Error (object sender, EventArgs e)
17 {
18///The generation that runs when an unhandled error occurs
19
20}
void Session_Start (object sender, EventArgs e)
22 {
23//code to run when a new session starts
Application.Lock ();
application["Count" = Convert.ToInt32 (application["Count"]) + 1;
application["allusers"] = Convert.ToInt32 (application["AllUsers"]) + 1;
System.IO.FileStream fs = new System.IO.FileStream ("Count.txt", System.io.filemode.openorcreate, System.IO.File Access.readwrite);
system.io.streamwriter SW = new System.IO.StreamWriter (FS);
Sw.writeline (application["allusers"]);
Sw.close ();
Fs.close ();
Application.UnLock ();
33}
34
void Session_End (object sender, EventArgs e)
36 {
Panax Notoginseng Application.Lock ();
application["Count" = Convert.ToInt32 (application["Count"])-1;
Application.UnLock ();
40
41}
Summarize:
Applicationd is typically used to store variables that are infrequently variable, such as the system menu, which is unlikely to change once a program is run.
Application there is a good place, such as the use of bad words, stored data will not be timed. Because it is also with the application is coexistence and death.
A few commonly used variables:
Application is an application-level variable that is used when communication between multiple users
Session is a user variable that allows a user to save data to another page when they visit multiple pages, as long as the user does not log off
ViewState page variables, equivalent to page global variables, but once you exit the current page, it is lost