hahacjh
既然选择了远方 便只顾风雨兼程

1.使用IsPostBack属性避免不必要的执行操作

 

代码
//只要有用花交互就会执行这个事件
void Page_Load(Object sender, EventArgs e) {
if (!Page.IsPostBack) {
String query
= "select * from Authors where FirstName like '%JUSTIN%'";
myCommand.Fill(ds,
"Authors");
myDataGrid.DataBind();
}
}

 

2.关闭不必要的Session状态(当用户在应用程序的 Web 页之间跳转时,存储在 Session 对象中的变量将不会丢失)

 

<%@ Page EnableSessionState="false" %>

 

3.注意使用Server Control

不必要时(不需要用户交互)可以不使用Server Control不必要时可以关闭ViewState(生命周期仅为当前页面)

EnableViewState设置为false 当回发时控件的状态会恢复到aspx页的初始设置

<asp:datagrid EnableViewState="false“ runat="server"/> 

//关闭整个页面的ViewState

<%@ Page EnableViewState="false"%>

4.不要用Exception控制程序流程

5.禁用VB和JScript动态数据类型

<%@ Page Language="VB" Strict="true" %>

6.尽量使用存储过程数据访问

7.只读数据访问不要使用DataSet

使用SqlDataReader代替DataSetSqlDataReader是read-only, forward-only

8.关闭ASP.NET的Debug模式

9.使用ASP.NET Output Cache缓冲数据

 

<%@ OutputCache Duration ="120" VaryByParam ="TextBox1;TextBox2" %>

 

Duration:缓冲时间 VaryByParam :当TextBox1和TextBook2中值的组合改变会增加Cache 如果设置为None 则无论TextBox1及TextBox2值是否改变页面都会使用缓存值,不会更新

 

VaryByControl:可把用户控件中应用<%@ OutputCache %>指令 具体参见OutputCache

 

10.数据缓冲Cache

 

代码
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));

 

 

posted on 2010-06-02 19:20  hahacjh  阅读(127)  评论(0编辑  收藏  举报