多使用DbDataReader,尽量不要使用DataTable/DataSet读取数据。 l for (int i = 0; i < dt.Rows.Count; i++) 应该这么写: for (int i = 0, len = dt.Rows.Count; i < len; i++)或 foreach (DataRow info in dt.Rows)推荐这种写法 l 少用try catch,用到try catch时要和 finally一起使用。 l 多使用using如: using (DbDataReader dr = Data.GetDbDataReader(strSql)) { while (dr.Read()) { }; } l 大字符串操作请使用StringBuilder 少使用string,字符串比较用Compare,字符串相加用Concat,大字符串相加用StringBuilder Append。 l 变量要在先定义在使用,不要在循环内定义变量。如: 错误的写法是:for (int i = 1; i < 10; i++) { string s = i.ToString(); } 正确写法:string s = string.Empty; for (int i = 1; i < 10; i++) { s = i.ToString(); } 这里还有一个地方要注意的:在字符串相加的时候,如果有int类型的要先转成string类型在相加,减少不必要的装箱拆箱操作。 l 如果你使用的是HTML控件,需要禁用<%@ Page EnableViewState="false" AutoEventWireup="false" EnableSessionState="false",web.config <pages enableViewState="false" enableSessionState="false" /> l 使用foreach替代for l 操作数据库要使用存贮过程/视图。 l 多使用CACHE对数据缓存。这才是最关键的。NET提供:HttpContext.Current.Cache/HttpRuntime.Cache,共享缓存有velocity/ memcached l 可使用<%@ OutputCache Duration="60" 缓存页面,可使用Response.BufferOutput = true;/ <%@ Page Buffer="true" 输出缓冲。 l 可将站点生成静态面页,好处多多。 l 可使用URL重写成伪静态,提供rss/baidu-sitemap/google-sitemap服务,有利于搜索引擎收录。 l Ajax调用页面要使用.ashx一般处理程序,速度要比.aspx文件要快。Ajax请求要使用POST不要使用GET。 l 发布站点时DLL要Release版本,不要用Debug版本。 l IIS需要使用集成模式,不要使用经典模式。 l Web.config 加 <customErrors mode="On" /> 关闭错误提示。 l Web.config 加 <compilation debug="false" /> 关闭调试模式。 l 使用Server.Transfer替换Response.Redirect l 多使用泛型集合操作,少用ArrayList。 |