最近突然想把項目中新聞管理模塊做成靜態頁
首先制作一個模板頁
<!DOCTYPE html PUBLIC "
<html xmlns="
<head>
<title></title>
</head>
<body>
<div>
$content$
</div>
</body>
</html>
然後制作制作一個動態頁面
前台頁面主要代碼(Default
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default
<!DOCTYPE html PUBLIC "
<html xmlns="
<head runat="server">
<title></title>
</head>
<body>
<form id="form
<div>
<asp:TextBox ID="txtContent" runat="server" Height="
<br />
<asp:Button ID="btnMake" runat="server" OnClick="btnMake_Click" Text="生成靜態頁" />
</div>
</form>
</body>
</html>
後台頁面主要代碼(Default
protected void btnMake_Click(object sender
{
//替換掉模板中的特征字符
string mbPath = Server
Encoding code = Encoding
StreamReader sr = null;
StreamWriter sw = null;
string str = null;
//讀取
try
{
sr = new StreamReader(mbPath
str = sr
}
catch (Exception ex)
{
throw ex;
}
finally
{
sr
}
//根據時間自動重命名
string fileName = DateTime
str = str
//生成靜態文件
try
{
sw = new StreamWriter(Server
sw
sw
}
catch (Exception ex)
{
throw ex;
}
finally
{
sw
Response
}
}
當新聞量很大時這樣做勢必會增加服務器的存儲壓力
From:http://tw.wingwit.com/Article/program/net/201311/14283.html