性能提高小技巧
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();
????}2、關閉不必要的Session狀態
<%@ Page EnableSessionState="false" %>
3、注意使用Server Control,不必要時可以不使用Server Control
不必要時可以關閉ViewState
<asp:datagrid EnableViewState="false“ runat="server"/>
<%@ Page EnableViewState="false" %>
4、不要用Exception控制程序流程
try?
{?
????result?=?100?/?num;
}
catch?(Exception?e)?
{?
????result?=?0;
}
if?(num?!=?0)?
????result?=?100?/?num;
else
?????result?=?0;?5、禁用VB和JScript動態數據類型
<%@ Page Language="VB" Strict="true" %>
6、使用存儲過程數據訪問
7、只讀數據訪問不要使用DataSet
使用SqlDataReader代替DataSet,SqlDataReader是read-only, forward-only
8、關閉ASP.NET的Debug模式
9、使用ASP.NET Output Cache緩沖數據
(1)ASP.NET輸出緩沖
頁面緩沖
<%@OutputCache%>
Duration
VaryByParam
片斷緩沖
VaryByControl
(2)數據緩沖
過期依賴條件
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));
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();
????}2、關閉不必要的Session狀態
<%@ Page EnableSessionState="false" %>
3、注意使用Server Control,不必要時可以不使用Server Control
不必要時可以關閉ViewState
<asp:datagrid EnableViewState="false“ runat="server"/>
<%@ Page EnableViewState="false" %>
4、不要用Exception控制程序流程
try?
{?
????result?=?100?/?num;
}
catch?(Exception?e)?
{?
????result?=?0;
}
if?(num?!=?0)?
????result?=?100?/?num;
else
?????result?=?0;?5、禁用VB和JScript動態數據類型
<%@ Page Language="VB" Strict="true" %>
6、使用存儲過程數據訪問
7、只讀數據訪問不要使用DataSet
使用SqlDataReader代替DataSet,SqlDataReader是read-only, forward-only
8、關閉ASP.NET的Debug模式
9、使用ASP.NET Output Cache緩沖數據
(1)ASP.NET輸出緩沖
頁面緩沖
<%@OutputCache%>
Duration
VaryByParam
片斷緩沖
VaryByControl
(2)數據緩沖
過期依賴條件
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));
轉載于:https://www.cnblogs.com/shanvenleo/archive/2006/03/03/342089.html
總結
- 上一篇: AOL、WebEx共同开发新AIM即时通
- 下一篇: 在.Net framework下遍历XM