ASP.NET性能提高的技巧

1.Page_Load与IsPostBack
2.关闭不必要的Session状态
    <%@Page EnableSessionState = “false“%>
3.注意使用Server Control
           (1)不必要时可以不使用Server Control
           (2)不必要时可以关闭ViewState
                  <asp:DataGrid EnableState = “false“ runat = “Server“>
                  <%@Pagwe EnableViewState = “false“%>
4.不要用Exception控制程序流程
不好的写法
try
{
result = 100/num;
}
catch(Exception e)
{
result = 0;
}

正确的写法
if (num!=0)
{
result = 100/num;
}
else
{
result = 0;
}
因为Exception的开销很大.

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缓冲数据
           页面缓冲
            <%@OutputChche%>
            Duration
            VaryByParam
            片段缓冲
            VaryByControl

//
             <%@OutputCache  Duration =“60“ VaryByParam = “CityName“%>
10.数据缓冲
     过期依赖条件
Cache.Insert(“MyData“,Source,new CacheDependency(Server.MapPath(“authors.xml“)));
只有文件变化时,才重新读数据.
//
 Cache.Insert(“MyData“,Source,null,DataTime.Now.AddHours(1),TimeSpan.Zero);

Cache.Insert(“MyData“,Source,null,DataTime.MaxValue,TiemSpan.FromMinutes(20));

posted on 2004-09-02 16:02  sunshinea  阅读(696)  评论(0编辑  收藏  举报

导航