ASP.NET性能提高的技巧

博客强调要避免不必要的执行操作,虽未详细说明,但结合标签推测可能与ASP.NET开发中涉及的Dataset、DataGrid等对象在服务器端操作时相关,防止多余操作引发异常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 避免不必要的执行操作

*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;

 
*禁用VBJScript动态数据类型
*<%@ Page Language="VB" Strict="true" %>
*使用存储过程数据访问
*只读数据访问不要使用DataSet
*使用SqlDataReader代替DataSet
*SqlDataReaderread-only, forward-only
*关闭ASP.NETDebug模式
*使用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));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值