1、寫靜態網頁要先創建一個模板,在WebSet目錄下創建Template,然後創建一個
html網頁,標明title,Content,Data等。點擊WebSet網站點屬性把虛擬路徑改成
\
2、在BLL層寫一個創建文件的方法
需要引用System.IO和System.Web
static void CreateFile(string title, string content, string date,
string filename)
{
string path = HttpContext.Current.Server.MapPath
("Template/Aritcle.html");//獲得模板頁的路徑
string openfile = File.ReadAllText(path, Encoding.UTF8);
//用string類型的變量接受文件的所有行
string str = openfile.Replace("{Title}", title);
str = str.Replace("{Content}", content);
str = str.Replace("{Date}", date);
string createpaht = HttpContext.Current.Server.MapPath
("Article") + "\\" + filename;//新網頁的地址
using (StreamWriter sw = File.AppendText(createpaht))
{
sw.Write(str);
sw.Close();
}
}
3、創建一個文件夾存放生成的靜態網頁