asp.net、aspx速度性能優化
好多朋友說用 .net 做出來的網站速度慢,我也感覺大多aspx的站都是速度很卡,為什么呢?剛從網上收集的優化內容,希望對大家有幫助: 1.避免不必要的執行操作 Page_Load 和 IsPostBack void Page_Load(Object sender, EventArgs e) { // ...set up a connecti
好多朋友說用
.net做出來的網站速度慢,我也感覺大多aspx的站都是速度很卡,為什么呢?剛從網上收集的優化內容,希望對大家有幫助:
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();
}
關閉不必要的Session狀態
<%@ 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;
禁用
VB和JScript動態數據類型
<%@ Page Language="VB" Strict="true" %>
使用存儲過程數據訪問
只讀數據訪問不要使用DataSet
使用SqlDataReader代替DataSet
SqlDataReader是read-only, forward-only
關閉ASP.NET的De
bug模式
使用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.anti-gravitydesign.com