减少不必要的资源消耗:
CPU,内存
性能提高的技巧
1、避免不必要的执行操作
Page_Load 和 IsPostBack
2、关闭不必要的Session状态
<%@ Page EnableSessionState="false" %>
3、不必要时可以不使用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缓冲数据
ASP.NET输出缓冲
页面缓冲
<%@OutputCache%>
Duration
VaryByParam
片断缓冲
VaryByControl
ASP.NET输出缓冲
数据缓冲
过期依赖条件
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));
博客介绍了提升.NET和ASP.NET性能的技巧,包括避免不必要的执行操作、关闭不必要的Session状态和ViewState、不用Exception控制流程、禁用动态数据类型、使用存储过程、用SqlDataReader代替DataSet、关闭Debug模式以及使用输出缓存等,以减少资源消耗,提高CPU和内存性能。

4358

被折叠的 条评论
为什么被折叠?



