Asp. NET page transfer value (5): Application

Source: Internet
Author: User

The Application object is scoped to the whole global, which means it is valid for all users. It is valid throughout the application life cycle, similar to using global variables, so it can be accessed from different pages. It differs from the session variable in that the former is a global variable shared by all users, and the latter is a unique global variable for each user.

One might ask, since all users can use the application variable, where can he use it? Here's an example: the number of site visits. It can be manipulated when multiple requests are accessed.

  Pros: 1. Easy to use, consumes less server resources.

2. Not only can pass the simple data, but also can pass the object.

3. The size of the data volume is unlimited.

  Cons: 1. It is easy to be manipulated as a global variable. Therefore, the variables used by individual users are generally not application.

How to use: 1. Create the name and value you need to pass in the code of the source page construct the application variable: application["Nmae"]= "Value (Or Object)";

2. The code on the destination page uses the application variable to remove the passed value. Result = application["Nmae"]

  Note: The common lock and unlock methods are used to lock and unlock, in order to prevent concurrent modifications.

Indextest.aspx Background page:

1 Private void Btn_chuanzhi_click (object23 application[" name "] =4 }

Indextestlist.aspx Background page:

 1  private  void  Page_Load (object   sender, EventArgs e)  Span style= "color: #008080;"   >2  { 3  string   name;  4   Application.Lock ();  5  name = Application[ " name   ". ToString ();  6   Application.UnLock ();  7 } 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.