日期:2014-05-18  浏览次数:20571 次

关于整个网站生成静态页问题!!!

  把整个网站全生成为静态,有一个问题想不明白,就是分页显示的问题.当生成一个静态页面时,原来所有分页上面的内容都有了变化...怎么实现呢,不会生成一个静态文章,就把整个栏目的分页页面都生成一下吧..... 如果每增加\删除文章都把所有分页都生成一遍,给服务器的压力是巨大的。

  大型门户网站是不是有专门的生成静态软件?如何让每个栏目都相隔一定时间自动生成静态文件?网站全部生成静态页的思路是什么?有这类网站的例子吗?或者有生成静态页的asp、asp.net组件吗?

------解决方案--------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Mysqlserver;
using System.IO;
using System.Text;
namespace NewsAdd
{
public partial class Admin_AdminPanel_NewsAdd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
string strDate = DateTime.Now.ToString("yyMMdd") + "\" + DateTime.Now.ToString("yyyymmddhhmmss");
string strFileName = strDate + ".shtml";
string strTitle=Request.Form["Title"].ToString().Trim();
string strContent=Request.Form["Content"].ToString().Trim();
string[] content = strContent.Split(new Char[] ...{'|'});
int upbound = content.Length;
SqlServerDataBase db = new SqlServerDataBase();
bool success = db.Insert("insert into inNews(Title,Content,FilePath)values('" + strTitle + "','" + strContent + "','" + strFileName + "')", null);

string dir = Server.MapPath("../../"+"NewsFiles/"+DateTime.Now.ToString("yyMMdd"));
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}

try
{
for (int i = 0; i < content.Length; i++)
{
//string[] newContent = new string[4];
StringBuilder strhtml = new StringBuilder();
using (StreamReader sr = new StreamReader(Server.MapPath("../../" + "NewsFiles/") + "\template.html",Encoding.GetEncoding("gb2312")))
{
String oneline;
while ((oneline = sr.ReadLine()) != null)
{
strhtml.Append(oneline);
}
sr.Close();
}
DataSet ds = db.Select("select top 1 NewsId from inNews order by NewsId desc", null);
string strTable = "<table><tr><td>$upUrl</td><td>$Number</td><td>$downUrl</td></tr></table>";
string FilePath="";
strhtml = strhtml.Replace("$Title", strTitle);
strhtml = strhtml.Replace("$NewsId", ds.Tables[0].Rows[0]["NewsId"].ToString());
strhtml = strhtml.Replace("$Time", DateTime.Now.ToString("yyyy/MM/dd"));
strhtml = strhtml.Replace("$Content", content[i]);
string strNumber = "";
for (int m = 1; m <=upbound; m++)
{
if (m == 1)
strNumber = strNumber + " ["+"<a href=" + "../" + strDate + ".shtml" + ">" + m + "</a>"+"] ";
else
{
int n = m - 1