Some optimal performance methods for usual use in ASP.NET

xiaoxiao2021-03-06  67

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 the session status of the page

<% Page enablesessionState = "false"%>

l Disable the session state of the application

In the sessionState configuration section of the application's web.config file, set the MODE property to OFF.

which 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 the control

l For the page

<% 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: Disabling VB and JScript dynamic data types

Variable data types should always be displayed, which can save the execution time of the program. To do this, you can write in front of the page: <% @ page language = "vb" strake = "true"%>

6: Complete data access using the stored procedure

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 for ASP.NET

To facilitate development debugging, VS.NET is open for 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 is:

N page buffer

An example: Query the weather in Beijing. 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.

the way:

u <% @ outputcache%>: Indicate page Use buffer

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's weather, in order to avoid reading to the wrong buffer, you can use this code to buffer the weather in multiple cities:

<% @ OutputCache Duration = 60 VarybyParam = "CityName"%>

This indicates that multiple data is buffered according to the CITYNAME parameter in the page URL.

n pieces buffer

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 controls

Different buffers can be implemented depending on the C attribute of Control.

n Data buffer

N-buffered expired dependencies

In a sense, Cache and Applications are the same, all of which are public objects. 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 dependence

Cache.Insert ("MyData", SOURCE

, New Cachedependency (Server.Mappath ("Authors.xml"))))))))))))

The meaning of this code is that the buffer MyData is always valid when the authors.xml file does not change.

U time reliance

It is an absolute expiration to set up 1 hour.

Cache.Insert ("MyData", Source, NULL

, DateTime.now.addhours (1), Timespan.zero;

u relative expiration

When Dataset is no longer changed for 20 minutes, the expiration is buffered.

Cache.Insert ("MyData", Source, NULL

, DateTime.maxvalue, Timespan.fromminutes (20));

Author Blog:

http://blog.9cbs.net/superhasty/

related articles

Some optimized performance methods in ASP.NET, beautiful OWC chart C # operation Excel method (1) Implementing server-side multi-thread Socket Server uses XML technology to implement OWC's display (2)

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

New Post(0)