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));
相关文档:
一).创建部署项目
1. 在“文件”菜单上指向“添加项目”,然后选择“新建项目”。
2. 在“添加新项目”对话框中,选择“项目类型”窗格中的“安装和部署项目”,然后选择“模板”窗格中的“安装项目”。在“名称”框 ......
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 ......
偶尔使用,简单的记录下过程
1.下载Newtonsoft.Json.Net20.dll后,放入Asp.net项目Bin文件夹中.
Newtonsoft.Json.Net20,是一个Object/Json转换工具,这里用来把对象转换成Json格式字符串.
2.树节点Model对象,
public class TreeModel{
private string _i ......
在ASP.NET中,我们可以用下面的方法实现从数据库中读取图片并显示在页面上,方法如下:
SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
String sql="SELECT image from append where id='" + strID + "'";
&n ......
ASP.Net生成静态HTML页!
环境:Microsoft .NET Framework SDK v1.1
OS:Windows Server 2003 中文版
ASP.Net生成静态HTML页
在Asp中实现的生成静态页用到的FileSystemObject对象!
在.Net中涉及此类操作的是System.IO
以下是程序代码 注:此代码非原创!参考别人代码
//生成HTML页
public static bool W ......