Comprehensive Methods for ASP. NET code to improve performance

Source: Internet
Author: User

1. Avoid unnecessary operations. For example, use IsPostBack in Page_Load;
2. Minimize the use of server-side controls
3. disable unnecessary Page Sessions and ViewState of the Control <% @ Page EnableSessionState = "false" %>
4. Disable VB and JSP dynamic types <% @ Page Language = "VB" Strict = "true" %>
5. Use stored procedures
6. Use DateReader instead of DataSet
7. Disable ASP. Net Debug mode
8. Use the Output Cache buffer of ASP. Net
<% @ OutputCache Duration = 60 VaryByParam = "None" %>
<% @ OutputCache Duration = 60 VaryByParam = "TextBox1, TextBox2" %>
Note: Duration sets the Cache expiration time;
VarByParam is used to set whether the parameter changes. If None is used, all parameters use the same Cache. When TextBox1 is set, the Cache is cached based on different TextBox1 values. When multiple parameters exist, the Cache is combined;
9. Do not use Exception to control program processes
Try
{
Result = 100/num;
}
Catch (Exception e)

{
Result = 0;
}

If (num! = 0)
Result = 100/num;
Else
Result = 0;

Iv. Buffer classification:
1. Page buffering: Different buffering processes are performed based on VarByParam.
2. Fragment buffering: Use Page Buffering in the page control. When the same page control is used multiple times in a page, different buffer processing needs to be performed based on VarByControl.
3. Data Buffer: Cache (the range is the same as that of Application, all users)
Cache. Insert ("MyData", Source, null, new CacheDependency (Server. MapPath ("authors. xml ")));
Cache. Insert ("MyData", Source, null, DateTime. Now. AddHours (1), TimeSpan. Zero );
Cache. Insert ("MyData", Source, null, DateTime. MaxValue, TimeSpan. FromMinutes (20 ))

1. Avoid unnecessary operations
2. disable unnecessary Session Status
3. Do not use Server Control when Server Control is unnecessary.
4. Disable ViewState if not necessary
5. Do not use Exception to control program processes.
Try {
Result = 100/num;
}
Catch (Exception e ){
Result = 0;
}
6. Do not use DataSet to replace DataSet with SqlDataReader for read-only data access
7. Disable the Debug mode of ASP. NET. The debug mode in web. config must be false, and the dll file compilation must be generated into a release version.
8. Use ASP. NET Output Cache to buffer data
9. buffer a large number of rarely updated data
9. Try to use stored procedure data for access
10. Static pages are not dynamic.
11. The effects implemented with JS are implemented with JS, and the result of rollback can be reduced when implemented on the client.
12. Switch to Server. Transfer without Response. Direct
13. Do not open or create an ADO. NET object during one use. Try to use a Connection, Command, or DataReader. Remember to close or release the object immediately when you no longer call the database data.
14. How many data sets are required to avoid non-pagination of fields
15. Do not use DataSet or DataGrid.
16. Run on win2003 Enterprise Edition

I don't need to mention the reason for 1.
2. Reduce memory consumption
3. Reduce the time when server control is interpreted as html.
4. Reduce the amount of hidden data added during transmission and reduce the number of transmitted files.
5. Why not let it hit the south wall?
6SqlDataReader is more efficient than DataSet
7. It is the version that does not apply Debug.
8. The page buffered by the Output Cache is faster than the static one (no file is read from the Memory Output directly)
9. Put the same data in advance and put it in memory faster than in a database or file.
9 The stored procedure is pre-optimized and compiled by the database.
10. Why should I explain it first?
11. I mean to let you go back and forth a few times. Would you like?
12Response. Direct needs to return to the customer to report
13 you have a pen in your hand, but you put it down before writing, and then change it
14.
15 I think the DataGrid is too fancy. DataSet is used to cache data very well. It will be wasted if you change it frequently.
16win2003 Enterprise Edition is an operating system integrated with. NET.

1. disable unnecessary Session status.
2. if not necessary, Server Control is not used. Disable the View State if not needed.
3. Do not use exception handling to control program processes. In many cases, conditional judgment can be used.
4. Disable Dynamic Data Types of VBS and JS.
5. Disable Debug mode.
6. Use OutputCache.
Data access:
1. Use stored procedures whenever possible.
2. Do not use DateSet for read-only data access.
3. database design room. Try to make each module and table independent. To facilitate database distribution in the future.

Related Article

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.