看了 Asp.net 静态页面生成(1)----模板生成  的朋友 肯定要问 那么第二种生成方式是怎么样的?
那就是 动态页生成
      二、动态页面生成
      动态页面生成,就是采用动态页面生成静态页面,主要用于已有的动态站点静态化。对原来站点改动较小
      实现思想:重载动态页面的Render() 函数,在生成页面代码时将代码写到我们的静态页面中。可以参考   "孟子E " 的解决方法 
                    还有就是修改链接,将原来的动态链接该为静态链接
      优点:实现比较简单,对原来站点改动较小,生成管理器可以部署在客户端。
      缺点:性能低、生成速度慢。
      现在我们详细讲解如何将一个现有的网站更改为可以生成的。我们假设网站的分类只有一级,生成目录页和文章页。
      首先建立一个页面基类 EnableCreated 类 实例代码:

然后需要生成的页面继承这个基类

 

Asp.net 静态页面生成(2)----重载生成using System;
Asp.net 静态页面生成(2)----重载生成
using System.Data;
Asp.net 静态页面生成(2)----重载生成
using System.Configuration;
Asp.net 静态页面生成(2)----重载生成
using System.Web;
Asp.net 静态页面生成(2)----重载生成
using System.Web.Security;
Asp.net 静态页面生成(2)----重载生成
using System.Web.UI;
Asp.net 静态页面生成(2)----重载生成
using System.Web.UI.WebControls;
Asp.net 静态页面生成(2)----重载生成
using System.Web.UI.WebControls.WebParts;
Asp.net 静态页面生成(2)----重载生成
using System.Web.UI.HtmlControls;
Asp.net 静态页面生成(2)----重载生成

 

文件名:Category.aspx


文件名:Category.aspx.cs

 

Asp.net 静态页面生成(2)----重载生成using System;
Asp.net 静态页面生成(2)----重载生成
using System.Data;
Asp.net 静态页面生成(2)----重载生成
using System.Configuration;
Asp.net 静态页面生成(2)----重载生成
using System.Collections;
Asp.net 静态页面生成(2)----重载生成
using System.Web;
Asp.net 静态页面生成(2)----重载生成
using System.Web.Security;
Asp.net 静态页面生成(2)----重载生成
using System.Web.UI;
Asp.net 静态页面生成(2)----重载生成
using System.Web.UI.WebControls;
Asp.net 静态页面生成(2)----重载生成
using System.Web.UI.WebControls.WebParts;
Asp.net 静态页面生成(2)----重载生成
using System.Web.UI.HtmlControls;
Asp.net 静态页面生成(2)----重载生成
Asp.net 静态页面生成(2)----重载生成
public partial class Category : EnableCreated

周末了,写点开发经验大家分享
      废话少说,开门见山。静态页面生成技术是很多大网站采用的技术。用于大型网站的访问量特别高,采用动态页面难免服务器负担很重,负载大的时候可能down机。人们想出了采取以前的静态页面,这样可以减少服务器运算负载,但是一个一个页面的做肯定人工成本太高。于是乎就出现了静态页面生成技术。
      静态页面生成的实现方法大致可以分为两种
      一、模板生成
      实现思想:提前把网页的公共部分写好,做成一个模板,而不同的部分采用特殊字符代替。当需要生产的时候,用程序去读取模板,然后去数据库中找到需要的数据替换模板中的特殊字符。生成真正的网页然后存在网站的目录下。 

      有点:效率高,生成速度快。
      缺点:需要在网站建设之前就确定采用此方法生成。对于已建好的动态站点改版为此方法 工作量大。
      实例代码:
Article.Templete.txt

 

Asp.net 静态页面生成(2)----重载生成<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Asp.net 静态页面生成(2)----重载生成
<html xmlns="http://www.w3.org/1999/xhtml">
Asp.net 静态页面生成(2)----重载生成
<head>
Asp.net 静态页面生成(2)----重载生成    
<title><@Title@></title>
Asp.net 静态页面生成(2)----重载生成
</head>
Asp.net 静态页面生成(2)----重载生成
<body>
Asp.net 静态页面生成(2)----重载生成    
<table border="0" cellpadding="0" cellspacing="0" width="980">
Asp.net 静态页面生成(2)----重载生成        
<tr>
Asp.net 静态页面生成(2)----重载生成            
<td style="height: 200px">
Asp.net 静态页面生成(2)----重载生成                header
Asp.net 静态页面生成(2)----重载生成            
</td>
Asp.net 静态页面生成(2)----重载生成        
</tr>
Asp.net 静态页面生成(2)----重载生成        
<tr>
Asp.net 静态页面生成(2)----重载生成            
<td>
Asp.net 静态页面生成(2)----重载生成                
<table border="0" cellpadding="0" cellspacing="0" width="980">
Asp.net 静态页面生成(2)----重载生成                    
<tr>
Asp.net 静态页面生成(2)----重载生成                        
<td>
Asp.net 静态页面生成(2)----重载生成                        
<@Title@>
Asp.net 静态页面生成(2)----重载生成                        
</td>
Asp.net 静态页面生成(2)----重载生成                    
</tr>
Asp.net 静态页面生成(2)----重载生成                    
<tr>
Asp.net 静态页面生成(2)----重载生成                        
<td>
Asp.net 静态页面生成(2)----重载生成                        
<@Content@>
Asp.net 静态页面生成(2)----重载生成                        
</td>
Asp.net 静态页面生成(2)----重载生成                    
</tr>
Asp.net 静态页面生成(2)----重载生成                    
<tr>
Asp.net 静态页面生成(2)----重载生成                        
<td>
Asp.net 静态页面生成(2)----重载生成                        剪辑:
<@Editor@>&nbsp;&nbsp;&nbsp;&nbsp;访问次数:<@Hits@>
Asp.net 静态页面生成(2)----重载生成                        
</td>
Asp.net 静态页面生成(2)----重载生成                    
</tr>
Asp.net 静态页面生成(2)----重载生成                
</table>
Asp.net 静态页面生成(2)----重载生成            
</td>
Asp.net 静态页面生成(2)----重载生成        
</tr>
Asp.net 静态页面生成(2)----重载生成        
<tr>
Asp.net 静态页面生成(2)----重载生成            
<td style="height: 100px">
Asp.net 静态页面生成(2)----重载生成                footer
Asp.net 静态页面生成(2)----重载生成            
</td>
Asp.net 静态页面生成(2)----重载生成        
</tr>
Asp.net 静态页面生成(2)----重载生成    
</table>
Asp.net 静态页面生成(2)----重载生成
</body>
Asp.net 静态页面生成(2)----重载生成
</html>
Asp.net 静态页面生成(2)----重载生成

 


生成函数

 


然后再访问这个页面的时候带上一个参数  Category.aspx?id=12&Create=true
从服务段可以得到一个数字 1 或者 0,1表示生成成功,0表示生成失败。
注意 第一行 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Category.aspx.cs" Inherits="Category" EnableViewState="false" %>
中的EnableViewState="false"   。因为要生成静态页面阿。所以这个地方就不需要 ViewState 了
下一节讲解如何编写 生成器  待续
 

 

相关文章: