background
I am an ASP., temporarily began to learn ASP. NET, in this record I personally knock code, not much reference value, please see the pots of friends for me to support me a bit, thank you. Session Introduction
The Application object is used to hold information that is shared with all users, such as the number of web logins.
When modifying the Application object, lock unlock is required to prevent the simultaneous operation from causing the problem.
The life cycle of application object members ends when IIS is closed or cleared using the clear method.
Application Pass Value
describe the number of people who entered the site application records.
Create a new global variable file, Globle.asax, to write code in three events
voidApplication_Start (Objectsender, EventArgs e) { //code to run when the application startsapplication["Cuscount"] =0; } voidSession_Start (Objectsender, EventArgs e) { //code to run when a new session is startedApplication.Lock (); application["Cuscount"] =(int) application["Cuscount"] +1; Application.UnLock (); }voidSession_End (Objectsender, EventArgs e) { //The code that runs at the end of the session. //Note: Only the sessionstate mode in the Web. config file is set to//InProc, the Session_End event is not raised. If the session mode is set to StateServer//or SQL Server, the event is not raised. Application.Lock (); application["Cuscount"] = (int) application["Cuscount"] -1; Application.UnLock (); }
Then write a new Web form, write method
protected void Page_Load (object sender, EventArgs e) { Response.Write (" Welcome, section " + application["cuscount " " bit customer <br/> " ); }
Let's introduce application. Retrieve data by index
Use previous page, write method
protected voidPage_Load (Objectsender, EventArgs e) {Response.Write ("welcome you, the first"+ application["Cuscount"] +"Customers <br/>"); Application.add ("Key1","Value1"); Application.add ("Key1","Value1"); Application.add ("Key1","Value1"); for(intindex =0; Index < Application.count; index++) {Response.Write (Application.getkey (Index)+": "); Response.Write (Application.get (Index)+"<br/>"); } }
This page shows
Asp. NET rookie Road of application small example