日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

怎么将aspx网站改为静态页面?

發布時間:2024/1/17 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 怎么将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
{

/// <summary> ///html 的摘要說明 /// </summary> public class Tohtml {public Boolean writehtml(string url,string str){System.IO.StringWriter swHtml = new System.IO.StringWriter();HttpContext.Current.Server.Execute(url + str, swHtml);// System.Web.HttpUtility.HtmlEncode(url + str); String file1 = str.Substring(0, 5) + ".html";string contentStr = swHtml.ToString();//string filePath = Server.MapPath("/");string filePath = HttpContext.Current.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;System.IO.StreamWriter sWrite = new System.IO.StreamWriter(filePath, true, Encoding.GetEncoding("UTF-8"));sWrite.Write(contentStr);sWrite.Flush();sWrite.Close();return true;} }

}

OK,可以調用了,除了自己更改就不用點生成就OK了

總結

以上是生活随笔為你收集整理的怎么将aspx网站改为静态页面?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。