asp.net性能
1.关闭不必要的Session
<%@ Page EnableSessionState="flase"%>
2.关闭不必要的ViewState
<asp:DataGrid EnableViewState="false" runat="server">
如果页面级
<%@ Page EnableViewState="false"%>
3.不要使用Exception控制程序流程
Exception是很耗资源的
4.禁用VB和JScript动态数据类型
动态数据类型是要占用大量的CPU运行时间
<%@ Page Language="VB" Strict="true"%>
5.使用存储过程的数据访问
6.只读数据访问不要使用DataSet(DataSet是断开连接的,存储再内存中,所以资源的消耗巨大)
使用SqlDataReader代替DataSet
SqlDataReader是read-only,forward-only
7.关闭ASP.NET的Debug模式,部署时是再web.config中取消Debug.
8.ASP.NET输出缓冲
页面缓冲:
<% OutputCache Duration=60 VaryByParam="None"%>
Duration=延迟时间;
VaryByParam=控件id,例如VaryParam="TextBox1";
切不可作无为的缓冲;
片断缓冲 :VaryByControl
asp.net新的对象Cache于Application对象具有相同的作用域
Cache.Insert("MyData",Source,new CacheDependency(Server.MapPath("authors.xml")));
绝对过期
Cache.Insert("MyData",Source,null,DataTime.Now.AddHours(1),TimeSpan.Zero);
相对过期
Cache.Insert("Mydata",Source,null,DataTime,MaxValue,TimeSpan.fromMinutes(20));
相关文档:
获取 ASP.NET 提供的当前 Session 对象 ( HttpSessionState 类 )。该属性提供有关当前请求的会话的信息。为从 ASP.NET 应用程序请求页或文档的每个用户维护一个 Session 对象。当用户在应用程序中从一页移动到另一页时,存储在 Session 对象中的变量不会被放弃;相 ......
获取与该 Page 对象关联的 HttpResponse 对象。该对象使您得以将 HTTP 响应数据发送到客户端,并包含有关该响应的信息。
一、HttpResponse 类
封装来自 ASP.NET 操作的 HTTP 响应信息。
HttpResponse 类型公开以下成员。
构造函数
名称
说明
HttpResponse
基础结构。初始化 HttpRespons ......
12 ASP.NET MVC Best Practices
M
DomainModel != ViewModel
Use ActionFilters for “shared” data
V
Do NEVER user code-behind
Write HTML each time you can
If there is an if, write an HtmlHelper
Choose your view engine carefully
C
Delete the AccountController
Isolate Controllers fro ......
先看看ASP.NET页面刷新的实现方法:
第一:
private void Button1_Click( object sender, System.EventArgs e ) { Response.Redirect( Request.Url.ToString( ) ); } 第二:
private void Button2_Click( object sender, System.EventArgs e ) { Response.Write( " < script language=javascript>window.locatio ......