避免不必要的执行操作
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 状态
不要用 Exception 控制程序流程
try {
result = 100 / num;
}
catch (Exception e) {
result = 0;
}
if (num != 0)
result = 100 / num;
else
result = 0;
禁用 VB 和 JScript 动态数据类型
页面缓冲
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));