ASP. NET development practices-performance and caching

Source: Internet
Author: User

1. Use the IsPostBack attribute to avoid unnecessary operations.

 

Code

 // This event will be executed as long as the interaction is useful.
Void Page_Load (Object sender, EventArgs e ){
If (! Page. IsPostBack ){
String query = "select * from Authors where FirstName like '% JUSTIN % '";
MyCommand. Fill (ds, "Authors ");
MyDataGrid. DataBind ();
}
}

 

2. disable unnecessary Session states (when a user redirects between Web pages of an applicationSessionThe variables in the object will not be lost)

 

 <%@ Page EnableSessionState="false" %>

 

3. Use Server Control

You can disable ViewState (the life cycle is only the current page) when you do not need to use Server Control)

EnableViewState is set to false. When sending back, the status of the controller is restored to the initial setting on the aspx page.

<Asp: datagrid EnableViewState = "false" runat = "server"/>

// Close the ViewState of the entire page

<% @ Page EnableViewState = "false" %>

4. Do not use Exception to control program processes

5. Disable VB and JScript Dynamic Data Types

<%@ Page Language="VB" Strict="true" %>

6. Try to use stored procedure data for access

7. Do not use DataSet for read-only data access

Use SqlDataReader to replace DataSetSqlDataReader with read-only, forward-only

8. Disable ASP. NET Debug mode

9. use ASP. NET Output Cache to buffer data

 

 <%@ OutputCache Duration ="120"  VaryByParam ="TextBox1;TextBox2" %>

 

Duration: buffer time VaryByParam: When the combination of TextBox1 and TextBook2 is changed, the Cache will be added. If it is set to None, the Cache value will be used regardless of whether the TextBox1 and TextBox2 values change.

 

VaryByControl: You can apply the <% @ OutputCache %> command to the user control. For more information, see OutputCache.

 

10. data buffer Cache

 

Code

 Cache.Insert("MyData", Source, 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));

 

 

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.