Some optimal performance methods for usual use in ASP.NET

xiaoxiao2021-03-06  85

Some optimal performance methods for usual use in ASP.NET

ASP.NET caching mechanism has a great improvement compared to ASP, this document emphasizes how to use ASP.NET cache to get the best performance. 1: Don't use unnecessary sessions

As in ASP, don't use the session when you don't have need. You can disable session status for the entire application or page: l Disable page Session Status <% Page EnableState = "false"%> <% page enablessionState = "false"%> l Disable the application's session state in the application's web. In the sessionState configuration section of the config file, set the MODE property to OFF. That is:

2: Do not use unnecessary Server Control

Among the ASP.NET, a large number of server-side controls are convenient for program development, but it may also result in performance loss, because the user operates a server-side recipient process. Therefore, it is not necessary to use Server Control.

3: Do not use unnecessary viewState

By default, ASP.NET enables ViewState (view status) for all Server Control. But ViewState needs to save some information on the client, which causes performance consumption. You must consider the viewState when you have to use Server Control. There are two ways to prohibit viewState: Disable ViewState for the entire page or a single control. l For controls

l For page <% page enableviewstate = "false"%> <% page enableViewState = "false"%> 4: Do not use the Exception control program process

Some programmers may use an exception to implement some process controls. E.g:

Try {result = 100 / num;} catch (exception e) {result = 0;}, but in fact, Exception is very consuming system performance. Unless necessary, abnormal control should not be used to implement the program process. The above code should be written as:

IF (Num! = 0) Result = 100 / NUM; Else Result = 0; 5: Disable VB and JScript Dynamic Data Types

Variable data types should always be displayed, which can save the execution time of the program. To this end, you can write in front of the page: <% @ page language = "vb" strict = "true"%> <% @ page language = "vb" strict = "true"%> 6: Using stored procedures Complete data access

7: Read-only Data Access Do not use DataSet.

Dataset acts as a powerful, supporting offline database, which is relatively large for performance overhead. Other data sets in the .NET can be used in a specific occasion. n Use SqldataReader instead of DataSet; n SqlDataReader is Read-Only, Forward-Only. 8: Close the Debug mode of ASP.NET For easy development debugging, VS.NET is open to Debug mode by default. When deploying an application, you should close the debug mode, which will effectively improve application performance. 9: Use the ASP.NET OUTPUT CACHE buffer data;

Providing buffering function is a very powerful feature in ASP.NET. I have seen some evaluation: ASP.NET program performance is several times more than Sun's JSP application performance, in fact, the evaluation program is very important to use a lot of ASP.NET buffer. The common buffer mode in ASP.NET has: N page buffers an example: query Beijing's weather. Because weather data is relatively predetermined within a certain period of time. When the weather in Beijing is the first time in the web program, the application may be called a remote WebService to get weather information. The subsequent users can get current weather information from the buffer. This will greatly improve performance and reduce the pressure of the server. Method: u <% @outputcache%>: Indicates that the page uses buffers. u DURATION: Controlling the time of the buffer, unit is minutes. u VarybyParam: The basis for indicating whether the buffer is used. For example, if the first user queries Beijing's weather, the weather is stored in Beijing. When the second user queries Shanghai weather, to avoid reading the wrong buffer, you can use such code to buffer weather: <% @ outputcache duration = 60 varybyparam = "cityname"%> <% @ OutputCache Duration = 60 VarybyParam = "cityname"%> This indicates that multiple data is buffered according to the CITYNAME parameter in the page URL. n Pieces in ASP.NET, in addition to using buffers within the page range, you can also use the Output Cache parameter to use the Output Cache parameter for user control. Similarly, the same type of control in a page can also have multiple different buffers. Different buffers can be implemented according to parameters. For example, for control can achieve different buffers according to different C properties.

n Data buffer

In a sense, Cache and Application are a public object in a sense, Cache and Applications are a public object. In order to obtain a balance between buffer and data validity, a reasonable setting of the buffer expiration strategy can be made as needed. U file relying on cache.insert ("MyData", Source, New Cached Assency)) The meaning of this code is that the buffer MyData is always valid when the authors.xml file does not change.

U Time relying on setting 1 hour after expiration, this is an absolute expiration. Cache.insert ("MyData", Source, Null, DateTime.now.addhours (1), Timespan.zero; U relatively expired dependencies When DataSet is no longer changed for 20 minutes, the expiration will be buffered. Cache.Insert ("MyData", Source, Null, DateTime.maxValue, Timespan.fromminutes (20));

转载请注明原文地址:https://www.9cbs.com/read-120757.html

New Post(0)