The release number of this article has been CHS311515
For Microsoft Visual Basic .NET versions of this article, see
309018.
This task content
summary
Use the Application object to use the cache object to use the appsettings object Other Remarks Reference
Summary This step-by-step guide demonstrates how to pass
APPLICATION,
Cache and
Appsettings object stores data within the application range. Data within the application range refers to data that can be used throughout the web application.
Back to top
Use Application objects
Create a new Visual C # ASP.NET web application. Add a TextBox control to WebForm1.aspx. TextBox1 will be created by default. Add the following code to the Page_Load event: TextBox1.text = Application ["abc"]. TOSTRING (); Add the following code to the application_start event in the code hidden module of the global.asax file: Application [ABC "] = "hi"; compiled the project. View WebForm1.aspx in your browser.
Back to top
Use cache objects
Create a new Visual C # ASP.NET web application. Add a TextBox control to WebForm1.aspx. TextBox1 will be created by default. Add the following code to the Page_Load event: TextBox1.text = cache ["abc"]. TOSTRING (); add the following code to the application_start event in the code hidden module of the global.asax file: context.cache.insert (" ABC "," Hello ", Null, DateTime.maxValue, Timespan.zero; Note: When using the Cache object inside the global.asax file, you must access it via a Context object such as Context.cache. Compile the project. View WebForm1.aspx in your browser.
Back to top
Use appsettings objects
Create a new Visual C # ASP.NET web application. Add a TextBox control to WebForm1.aspx. TextBox1 will be created by default. Add the following code to the Page_Load event: TextBox1.text = configurationSettings.appsettings ["abc"]. TOSTRING () Add the following code to the same code to hide the top: use system.configuration; in the web.config file , Find the following:
appsettings> Compiles the project. View WebForm1.aspx in your browser.
Back to top
Other memo
If you modify the Global.asax or Web.config file (even "Notepad"), the web application will restart. This will clear all data stored in memory, such as application and cache data, and if the session data is stored in memory (ie, if you are using Inproc session status mode), the session data is included. The Cache object has advanced memory management. For demonstration purposes, this article uses DateTime.MaxValue as absolute expiration time. Therefore, this code does not utilize these memory management functions in optimal mode. For additional information about the Cache object, click the article number below to view the article in the Microsoft Knowledge Base: 307225 Info: ASP.NET CACHING OVERVIEW (ASP.NET Cache Overview) How to know which method is best for you? Why do you choose this method without choosing another? This ability to modify the value of the variable in the code is advantageous in the application run. This is harmful if multiple processors (CPUs) or multiple servers are running your web application. Each CPU or server maintains its respective variables. If you change the value of a variable, the change does not affect any other value. Use the Cache object: Read / Write - You can add or modify the items in the code during the application run. To imitate the mode of read-only code, set the value of the variable in the Application_Start event, and will not change it anywhere. Cache objects becomes more interesting when you use its memory management. If your data needs to be regularly or occasionally refreshed, this object has many functions based on time and dependent, which can call the callback function to let you use to refresh the data. Alternatively, if some functions generate a large amount (or unable) data reused, the cache maintains the data at a lower priority and clears it when other objects require memory. Using Application object: Read / Write - You can add or modify the items in the code during the application run. To imitate the mode of read-only code, set the value of the variable in the Application_Start event, and will not change it anywhere. The Application variable is suitable for storing static items that need to be globally accessed but can be modified at runtime. Using AppSettings Object: Read Only - Items read from the web.config file when the application is just started. You cannot add or modify your application without restarting the application. Similar to Application object variables, AppsetTINGS is best suited for items that remain static and easier in one place.
Back to top
Refer to additional information, click the following article number to view the article in the Microsoft Knowledge Base:
307626 INFO: ASP.NET Configuration overview (ASP.NET Configuration Overview)
307598 INFO: ASP.NET State Management overview (ASP.NET Status Management Overview)
307225 INFO: ASP.NET CACHING OVERVIEW (ASP.NET Cache Overview) For more information, see the following topics in the Microsoft .NET Framework Software Development Kit (SDK) document:
Application status http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguidnf/html/cpConApplicationState.asp ASP.NET Cache http://msdn.microsoft.com/library /default.asp?url=/library/en-us/dnaspnet/html/ASP04262001.ASP ASP.NET cache function http://msdn.microsoft.com/library/default.asp?url=/library/en-us /cpguidnf/html/cpConaspCachingFeatures.asp Back to top
The information in this article applies to:
Microsoft ASP .NET (included in .NET Framework) Microsoft Visual C # .NET (2002)
Recent Updated: 2002-2-24 (1.0) Keyword kbcaching kbdsupport KBGRPDSASP KBHOWTO KBHOWTOMASTER KBPERFORMANCE KBSTATATE KB311515