1.避免不必要的執行操作
Page_Load 和 IsPostBack void Page_Load(Object sender, EventArgs e) { // ...set up a connection and command here... if (!Page.IsPostBack) { String query = "select * from Authors where FirstName like '%JUSTIN%'"; myCommand.Fill(ds, "Authors"); myDataGrid.DataBind(); } } void Button_Click(Object sender, EventArgs e) { String query = "select * from Authors where FirstName like '%BRAD%'"; myCommand.Fill(ds, "Authors"); myDataGrid.DataBind(); }
<%@ Page EnableSessionState="false" %>
注意使用Server Control
不必要時可以不使用Server Control
不必要時可以關閉ViewState
<asp:datagrid EnableViewState="false“ runat="server"/>
<%@ Page EnableViewState="false" %>
不要用Exception控制程序流程
try { result = 100 / num; } catch (Exception e) { result = 0; } if (num != 0) result = 100 / num; else result = 0;
<%@ Page Language="VB" Strict="true" %>
使用存儲過程數據訪問
只讀數據訪問不要使用DataSet
使用SqlDataReader代替DataSet
SqlDataReader是read-only, forward-only
關閉ASP.NET的Debug模式
使用ASP.NET Output Cache緩沖數據
頁面緩沖
<%@OutputCache%>
Duration
VaryByParam
片斷緩沖
VaryByControl
數據緩沖
過期依賴條件
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));
鏈接最好都關..檢查你的SQL語句是否最優..不要SELECT * 這樣.列出你所用的字段
減少數據庫的壓力..訪問量大但是更新不是很快的頁面加一個頁面緩存,
速度慢一般就是數據庫慢了
只讀數據使用datareader,很多的數據庫操作使用存儲過程,
使用<%@outputcache Duration=60 VaryByParam="*"%>進行緩存
關閉debug模式
正確使用索引
if (!Page.IsPostBack)進行綁定不需要回傳的代碼
圖片不要太精確
主頁數據查詢比較多但更新不常用的可以使用aspx動態生成html頁面
控件不需要經常編程的 比如輸入控件等都使用HTML控件
開通鏡像服務
數據訪問 多用存儲過程
經常訪問的數據 采用高速緩存 (要適量)
session 值不要太多 注意管理
延伸閱讀
文章來源于領測軟件測試網 http://www.kjueaiud.com/