怎么将aspx网站改为静态页面?
生活随笔
收集整理的這篇文章主要介紹了
怎么将aspx网站改为静态页面?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
首先思路是在后臺點擊“生成靜態頁面” 轉換為靜態頁面
protected void Button2_Click(object sender, EventArgs e)
{DataSet ds = Getyuqian().GetList(0, "", "Tdate desc");//取列表數據string str="";if (ds != null && ds.Tables[0].Rows.Count > 0){for (int i=0; i < ds.Tables[0].Rows.Count-1; i++)//循環ID{str = ds.Tables[0].Rows[i]["id"].ToString();System.IO.StringWriter swHtml = new System.IO.StringWriter();Server.Execute("../../yuqiand.aspx?id="+str, swHtml);//獲取該數據生成頁面的htmlString file1 = str.Substring(0,5)+".html";//去ID前5位為頁面名字,因為我把ID加密了比較長string contentStr = swHtml.ToString();string filePath = Server.MapPath("/");//獲取網站本地的基目錄if (!System.IO.Directory.Exists(filePath)){System.IO.Directory.CreateDirectory(filePath);}//如果存在該頁面就刪除foreach (string file in System.IO.Directory.GetFiles(filePath)){if (file.Substring(file.Length-10,10) == file1){File.Delete(file);}}filePath += file1;//按UTF-8導入,不然亂碼System.IO.StreamWriter sWrite = new System.IO.StreamWriter(filePath, true, Encoding.GetEncoding("UTF-8"));sWrite.Write(contentStr);sWrite.Flush();sWrite.Close();}} }后來我想,添加數據和修改數據就自動生成頁面了,那么,使用次數就比較多就些個類來調用把
調用頁面:
Boolean boolx = false;Helper.Tohtml htmlto = new Helper.Tohtml();boolx = htmlto.writehtml("../../zyd.aspx?id=", model.id.ToString()); if (boolx == true){// AlertResponse("發布成功!", "list_qy.aspx");}類:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.IO;
using System.Text;
using System.ComponentModel;
namespace Helper
{
}
OK,可以調用了,除了自己更改就不用點生成就OK了
總結
以上是生活随笔為你收集整理的怎么将aspx网站改为静态页面?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HCharts随笔之简单入门
- 下一篇: HTTPS中SSL协议总结